Ok here is my situation. I am realy new to this stuff and dotn know crap to tell you the truth. But her eis my situation
Here is my code:
It reads in this file:Code:#include <iostream.h> #include <fstream.h> #include <stdlib.h> #include <string.h> void main() { ifstream inFile; ofstream outFile; char myInFile[20] = "a:\\input.txt"; // The inout file. char myOutFile[20] = "a:\\output.txt"; // The output file. inFile.open(myInFile); if(inFile){ cout << "\nInput file " << myInFile << " was succesfully opened!!!!" << endl; } else { cout << "\nInput File " << myInFile << " could not be opened!!!!" << endl; exit(-1); } outFile.open(myOutFile); if(outFile){ cout << "\nOutput file " << myOutFile << " was succesfully opened!!!!" << endl; } else { cout << "\nOutput File " << myOutFile << " could not be opened!!!!" << endl; exit(-1); } int account =0; char fName[20]; char lName[20]; float amount =0; char dummy; outFile << "This is the data that was read in." <<endl <<endl; inFile >> account >> fName >> lName >> amount; // Prime Read while(inFile){ outFile << account << ' ' << fName << ' ' << lName << ' ' << amount << endl; inFile >> account >> fName >> lName >> amount; } //while outFile << "\nThe end of the input!!!"; }
1001
Mary
Gist
12350.123
1002
John
Smith
2600.2291
1003
Nick
Dillon
271623.98
1004
Brad
Frazier
72.19
1005
Chris
Parish
81625.00
1006
Robin
Payne
1200.34
1007
Jamie
Lampe
961.80
1008
Melanie
Dixon
62199.71
1009
Terrance
Henderson
3928.10
1010
Mark
Cooper
1.25
And spits out this:
This is the data that was read in.
1001 Mary Gist 12350.1
1002 John Smith 2600.23
1003 Nick Dillon 271624
1004 Brad Frazier 72.19
1005 Chris Parish 81625
1006 Robin Payne 1200.34
1007 Jamie Lampe 961.8
1008 Melanie Dixon 62199.7
1009 Terrance Henderson 3928.1
1010 Mark Cooper 1.25
The end of the input!!!
Now what i have to do is make the output file print in alphabetical order by last name!!!
I dont know what to do.
Should i use qsort or what and how
Please help!!! THANK YOU!!!!