P
pavan734
Hi I have got a file "file_data.in" that contains the following data:
abcdef
I have a code that reads character by character & display it. But to
my surprise it is printing one character more at the end. I dont want
the last character to be printed. Here is the code I have written:
//code
FILE* input_file ;
input_file = fopen("file_data.in", "r");
char file_data;
cout << "Printing input data\n" ;
do
{
file_data = fgetc(input_file);
if(file_data == EOF)
{
cout << "break\n" ;
break;
}
cout << "File data = " << file_data << endl ;
}while(file_data !=EOF);
The output I got is :
Printing input data
File data = a
File data = b
File data = c
File data = d
File data = e
File data = f
File data =
break
abcdef
I have a code that reads character by character & display it. But to
my surprise it is printing one character more at the end. I dont want
the last character to be printed. Here is the code I have written:
//code
FILE* input_file ;
input_file = fopen("file_data.in", "r");
char file_data;
cout << "Printing input data\n" ;
do
{
file_data = fgetc(input_file);
if(file_data == EOF)
{
cout << "break\n" ;
break;
}
cout << "File data = " << file_data << endl ;
}while(file_data !=EOF);
The output I got is :
Printing input data
File data = a
File data = b
File data = c
File data = d
File data = e
File data = f
File data =
break