little help

This is a discussion on little help within the C++ Programming forums, part of the General Programming Boards category; Can I have a "little" help in the right way.... Write a program to generate personalized junk mail. The program ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    5

    little help

    Can I have a "little" help in the right way....

    Write a program to generate personalized junk mail. The program takes input both from an input file and from the keyboard. The input file contains the text of a letter, except that the name of the recipient is indicated by the three characters #N#. The program asks the user for a name and then writes the letter to a second file but with the three letters #N# replaced by the name. The three-letter string #N# will occur exactly once in the letter.

    Hint: Have your program read from the input file until it encounters the three characters #N#, and have it copy what it reads to the output file as it goes. When it encounters the three letter #N#, it then sends output to the screen asking for the name from the keyboard.


    this is what I got...

    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    
    
    int main()
    {
    	using namespace std;
    	
    	char infile[50], name[50];
    
    
    	ifstream instream;
    	ofstream outstream;
    
    
    cout << "Hello!\n";
    
    cout << "Please enter your name: ";
    cin >> name;
    
    	instream.open("infile.txt");
    	if (instream.fail())
    	{
    		cout << "Input file opening failed.\n";
    		exit(1);
    	}
    
    	outstream.open("outfile.txt");
    	if (outstream.fail())
    	{
    		cout << "Output file opening failed.\n";
    		exit(1);
    	}
    
    	instream >> "Enter your text: ";
    	outstream << "Your out stream is" << infile;
    
    	instream.close();
    	outstream.close();
    
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    Code:
    instream >> "Enter your text: ";
    That doesn't do anything. You need to read into a variable - probably a string or character. Try just reading in the letter and outputting it to cout first and see if you can get that working.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    Search the text until you find #. Check if Text[CurrentPosition+1] is N and Text[CurrentPosition+2] is #. If not, skip this # and search for the next.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21