Read one line at a time, they usualy end with '\n', so fgets() can be used, just make sure to allocate anough room for your line...
Something like:
Code:
#include <stdio.h>
#include <string.h>
#define LINE_LENGTH 1024
int main(int argc, char* argv[]){
char buffer[LINE_LENGTH +1];
FILE *fp;
int i = 1;
if(argc != 2){
printf("Usage: %s <file>\n", argv[0]);
return 0;
}
if(!(fp = fopen(argv[1], "r"))){
printf("Error opening file: %s\n", argv[1]);
return -1;
}
while(fgets(buffer, LINE_LENGTH, fp))
printf("Last letter besides '\\n' in line %d: %c\n", i++, buffer[strlen(buffer)-2]);
if(EOF == fclose(fp))
printf("Error closing file %s\n", argv[1]);
return 0;
}
Note: the above code has not been tested, it has
not been compiled, it was written directly into the composer window without any previus typechecking of any sort.. Your milage may vary.