c++ - Switch statement issue -



c++ - Switch statement issue -

i've made modifications , i'm having issue switch statement. functions supposed read random access files. when run program, displays menu , when take alternative outputs first alternative choose. if take option, doesn't output letters. how can prepare this?

//random-access files programme //this programme reads file beg end, end beg, beg 4th position, //8th 15th position, end 21st position, , 22nd position end #include <iostream> #include <fstream> using namespace std; void begtoend(fstream &, char); void endtobeg(fstream &, char); void begto4th(fstream &, char); void eighthto15th(fstream &, char); void endto21st(fstream &, char); void twenty2ndtoend(fstream &, char); int main() { char letters; //holds character int choice; fstream file("alphabet.txt", ios::in | ios::binary); //this opens file { cout << "enter 1 read origin end" << endl << "enter 2 read end beginning" << endl << "enter 3 read origin 4th position" << endl << "enter 4 read 8th 15th position" << endl << "enter 5 read end 21st position" << endl << "enter 6 read 22nd position end" << endl; cin >> choice; switch(choice) { case 1: begtoend(file, letters); break; case 2: endtobeg(file, letters); break; case 3: begto4th(file, letters); break; case 4: eighthto15th(file, letters); break; case 5: endto21st(file, letters); break; case 6: twenty2ndtoend(file, letters); break; } cout << endl; system("pause"); file.close(); //closes file } while(choice != 'n' && selection != 'n'); homecoming 0; } void begtoend(fstream &in, char letter) { in.seekg(0l, ios::beg); //displays origin end for(int = 0; < 25; i++) { in.get(letter); cout <<"beginning end: " << letter << endl; } } void endtobeg(fstream &in, char letter) { in.seekg(0, ios::end); //displays end origin int size = in.tellg(); (int i=1; <= size; i++) { in.seekg(-i, ios::end); letter=in.get(); cout << "end beginning: " << letter << endl; } } void begto4th(fstream &in, char letter) { in.seekg(0l, ios::beg); //displays origin 4th position for(int = 0; < 4; i++) { in.get(letter); cout << "beginning 4th letter: " << letter << endl; } } void eighthto15th(fstream &in, char letter) { in.seekg(7l, ios::beg); //displays 8th 15th position for(int = 0; < 7; i++) { in.get(letter); cout << "8th 15th letter: " << letter << endl; } } void endto21st(fstream &in, char letter) { in.seekg(0, ios::end); //displays end 21st position int size = in.tellg(); (int i=1; <= 5; i++) { in.seekg(-i, ios::end); letter=in.get(); cout << "end 21st: " << letter << endl; } } void twenty2ndtoend(fstream &in, char letter) { in.seekg(21l, ios::beg); //displays 22nd position end for(int = 0; < 5; i++) { in.get(letter); cout << "22nd end: " << letter << endl; } }

first of all, defined "choice" char, hence should utilize in case part this:

case '1':

or should define "choice" int. (remember '1' different 1)

second of all, should utilize escape character in file name when seek open files.

char* filename = "c:\\bla\\bla.txt";

or (without escape character)

char* filename = "c:/bla/bla.txt";

c++ function randomaccessfile

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -