Help with specific output function

This is a discussion on Help with specific output function within the C++ Programming forums, part of the General Programming Boards category; I didn't notice this until I recently tested it, but the function I did in a program is supposed to ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    Help with specific output function

    I didn't notice this until I recently tested it, but the function I did in a program is supposed to read a list of students that another function output, and then it is to output it in order by reference number. The output is in the form of
    "IDNumber LastName Firstname Email@mdcc.edu 6digrefNum"
    the first being the id number, second being last name, then first, then the e-mail, then the reference number. When I ouput it, it only captures the first id number and utputs that seperated. I want it so that it will caputre the first, output that and ignore all other numbers, then do similar with the other reference numbers.
    Code:
    void ReportOutput(ifstream & inFile, ofstream & outFile2, string SSN, string LastName, string FirstName, 
    				  string & semester, string & Email, int choice, int students, int ReferenceNum, int RefNum[])
    {	
    	 if (!inFile)
    		{
    			cerr << "File could not be opened" << endl;
    			exit(1);
    		}
    
    	   if (inFile==NULL)
    	   {
    		   cout<<"The file does not exist";
    		   exit(0);
    	   }
    
    
    	outFile2 << "\n\n\nReference Number  " << RefNum[0] << endl;
    	outFile2 << "\n\n\nSSN" << right << setw(20) << right << setw(20) << "Last"
    			<< right << setw(20) << "First  " << right << setw(20) << "E-mail@mdcc.edu\n";
    	
    	while (!inFile.eof())
    		{
    		inFile >> SSN >> LastName >> FirstName >> Email >> ReferenceNum;
    
    	if(ReferenceNum==RefNum[0])
    		{
    		outFile2 << right << SSN << right << setw(17) << LastName << right 
    			 << setw(16) << FirstName << right << setw(20) << Email;
    		break;
    		}
    		}
    	inFile.seekg(0, ios::beg);
    
    	int n;
    	for(n = 0; n!=40; n++)
    	{outFile2 << "\n";}
    
    		outFile2 << "Reference Number" << RefNum[1] << endl;
    		outFile2 << "\n\n\nSSN" << right << setw(20) << right << setw(20) << "Last"
    			<< right << setw(20) << "First  " << right << setw(20) << "E-mail@mdcc.edu\n";
    
    	while (!inFile.eof())
    		{
    	inFile >> SSN >> LastName >> FirstName >> Email >> ReferenceNum;
    
    	if(ReferenceNum==RefNum[0])
    		{
    		outFile2 << right << SSN << right << setw(17) << LastName << right 
    			 << setw(16) << FirstName << right << setw(20) << Email;
    		break;
    		}
    		}
    	inFile.seekg(0, ios::beg);
    
    	for(n = 0; n!=40; n++)
    	{outFile2 << "\n";}
    		outFile2 << "Reference Number" << RefNum[2] << endl;
    		outFile2 << "\n\n\nSSN" << right << setw(20) << right << setw(20) << "Last"
    			<< right << setw(20) << "First  " << right << setw(20) << "E-mail@mdcc.edu\n";
    
    	while (!inFile.eof())
    		{
    		inFile >> SSN >> LastName >> FirstName >> Email >> ReferenceNum;
    
    	if(ReferenceNum==RefNum[0])
    		{
    		outFile2 << right << SSN << right << setw(17) << LastName << right 
    			 << setw(16) << FirstName << right << setw(20) << Email;
    		break;
    		}
    		}
    }
    is there a problem with my code

    btw
    Code:
    int RefNum[3]{111111, 222222, 333333};

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    do you think it has something to do with the break?

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    I assume you want to read in data from a formated file line by line and output the formated data. One solution is a string object. You do not know the exact size of each item in each line. Maybe the email address requires more bytes than you have in the storage array. Maybe the second and third items are missing from a line.

    I recommend a string object and use find() to separate each item via space.

    Kuphryn

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    sorry for bumping hte old topic, but lets say I have 3 rows of information, and each line ends with the reference number. Lets say Line one reference is 111111, the second line ends with 222222, and the third is 333333.

    When the program reads the whole line, if the reference number 111..., 222..., or 333... it will out put only that on the first header. Then it reads it agian and does the same with the other. But it doesn't output correctly. I have tried using

    Code:
    inFile.close
    inFile.open()
    instead of
    Code:
    inFile.seekg(0, ios::beg);
    and I still get similar problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM
  3. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 07:55 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

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