Hi, all
I have a question regarding reading files
Once I get the code to open the file how can I get it to scan right to the first character of the last line of the .txt file?
thanx
Hi, all
I have a question regarding reading files
Once I get the code to open the file how can I get it to scan right to the first character of the last line of the .txt file?
thanx
-Ti22-
The only portable way is to read the file until you get to the last line:
Code:#include <stdio.h> #include <stdlib.h> int main ( void ) { char buf[BUFSIZ]; FILE *in = fopen ( "test.txt", "r" ); if ( in == NULL ) return EXIT_FAILURE; while ( fgets ( buf, sizeof buf, in ) != NULL ) ; printf ( "The last line is \"%s\"\n", buf ); printf ( "The first character of the last line is '%c'\n", buf[0] ); return 0; }
My best code is written with the delete key.