View Single Post
Old Feb 9th, 2007, 12:51 PM   #1
Lesliect6
Programmer
 
Join Date: Aug 2005
Posts: 68
Rep Power: 4 Lesliect6 is on a distinguished road
file reading anomaly

Hello,

I would like to know the cause of this anomaly in a recent code I made. The code opens a file, and reads the number of lines in it. It works with some files, and does not with others. The code snippet is the following :

...
#define NEXT_LINE 10
...
int main()
{
...
char c, str[256];
int lines=1;

ifstream fin;
cin >> str;
fin.open(str); 

while (fin.good())
{
    c=fin.get();
    if (c==NEXT_LINE) lines++;
}

cout << "The number of lines in the file : " << lines;
...

While this code works with a .txt and a .bak file I made for the program, it does not work with an .x and an .exe file. I don't know where I made the error, could you help me?

Thank you,
Leslie
Lesliect6 is offline   Reply With Quote