File is not read!
I am totally new to this programming stuff, and requesting u all ,to help me out in this .........
My Q is I have to take valid input FIle from the user ,and open it,until user presses -1 to exit........ or until he/she doesnt type the valid name (which in my case is "records.txt")......
My code is working ........but the problem is if I type valid name ,it get stucked.........
int number = 0;
string file = " ";
ifstream inputFile("records.txt", ios::in );
cout<<"Enter the file (-1 to end)"<<endl;
if(file != "records.txt" )
cout<<"File doesnt exist"<<endl;
if (file == "-1")
if (file== "records.txt")
adatabase(database,number);// populating the database//
cin.getline(buffer, SIZE, '\n');
I can't be volumes of help to you, as I could not get this to compile (I'm very new too). But it may get more of a response if you list your compiler and your include files.
Also, even though you have code in your program to make sure the user enters the correct file name, you do not appear to be making sure that the file can be opened (I don't know, the function you use may do that automatically).
Also, since you have a number of statements under your test to see that the user enters the correct file name, perhaps you could put a print statement of some kind after each one to see exactly where your program is getting stuck (if you haven't already tried that). If you have tried that you could reply with exactly what line of code was giving you issues
Okay... how 'bout tryin' this Bird:
file != "-1" or file == "records.txt"
strcmp(file, "-1") != 0 or strcmp(file, "records.txt") == 0
strcmp(char *s1, char *s2) returns:
< 0 if s1 < s2
> 0 if s1 > s2
== 0 if s1 == s2