I am trying to open a textfile and reading it char by char. Here is my code:
printf( "Opening the file test.txt in read mode" ) ;
fp = fopen ( "test.txt", "r" ) ; // opening an existing file
if ( fp == NULL )
{
printf ( "Could not open file test.txt" ) ;
return 1;
}
printf( "Reading the file test.txt" ) ;
while ( 1 )
{
c = fgetc ( fp ) ; // reading the file
if ( c == EOF )
break ;
printf ( "%c", c ) ;
}
printf("Closing the file test.txt") ;
fclose ( fp ) ; // Closing the file
The file test.txt exists in the same directory as the program (exe).
When I execute it, fopen() is always returning NULL. Can someone help me, what there could be wrong? Thank you.