okay here is my problem now
if the input is
then the output isCode:penny henry george sammy vanne
where did vanne go?Code:george henry penny sammy
my program as of now
Code://this program // //program4.cpp //my name. (im not going to tell you this) #include <fstream> #include <iostream> #include <string> using namespace std; // using standard namespace int main () { char file[20]; string str; string stri[100]; int quit =24; cout << "enter the name of the input file in the format filename.txt: " ; //user determines the file to write to cin >> file; cout << endl; fstream myfil (file); if (myfil.is_open()) { quit=0; } else quit=1; while (quit==1) // keeps the user from trying to write in a close file { cout << "file could not be opened. enter the name of another file in the format filename.txt:" ; //error message cin >> file; fstream myfil ("example.txt"); if (myfil.is_open()) { quit=0; } } for (int x=1; x<=100; x++) myfil >> stri[x-1]; bool swap; string temp; int bottom = 99; do { swap = false; for (int count = 0; count <= bottom; count++) { if (stri[count][0] > stri[count+1][0]) { temp = stri[count]; stri[count] = stri[count+1]; stri[count+1] = temp; swap = true; // indicates that a swap occurred } } bottom--; } while(swap != false); // loop repeats until a pass through the array with // no swaps occurs cout << "enter the name of the output file in the format filename.txt: " ; //user determines the file to write to cin >> file; ofstream myfile (file); if (myfile.is_open()) { quit=0; } else quit=1; while (quit==1) // keeps the user from trying to write in a close file { cout << "file could not be opened. enter the name of another file in the format filename.txt: " ; //error message cin >> file; ofstream myfile ("example.txt"); if (myfile.is_open()) { quit=0; } } for (int y =0; y<100; y++) { str = stri[y] ; if (str!="") myfile <<str << endl; } myfile.close(); myfil.close();// close the file return 0; }



LinkBack URL
About LinkBacks


