can someone please modify the following code?
can someone please modify the following code?
what I need the code to do is to sort customers' last names alphabetically, the code takes data from a text file that sorts it then it reads from a file.
I would rather the code not have an array because the text file store unlimited customers.
void sortPassengers()
{
int x;
int last, i, save;
char list[100];
ifstream myfile;
myfile.open("allCustomers.txt");
char output[100];
for (i=0; i<=9; i++)
if (myfile.is_open())
{
while (!myfile.eof())
{
myfile >> output;
cout<<output;
}
}
myfile.close();
for (last=8; last>=0; last--)
for (i=0; i<=last; i++);
if (list[i]>list[i+1])
{
save=list[i];
list[i]=list[i+1];
list[i+1]=save;
}
ofstream duplicate; //creates a new txt file that puts names.txt in alphabetical order
//writes text into file
duplicate.open("allCustomers.txt");
for (i=0; i<=3; i++)
duplicate <<output<<endl;
myfile.close();
return ;
}
Step by step
Solved in 2 steps with 1 images