How can I check if there is a newline character at the end of my file?
I've tried a couple things but none of them work. Can anyone show me how to do this please?
This is what I've tried so far. It is a regular text file, opened with "a+".
Code:
fseek(filepathA,-2,SEEK_END);
char newlinetest=fgetc(filepathA);
if (newlinetest >=' ' && newlinetest <='~')
fputc((int)'\n',filepathA);
fseek(filepathA,0,SEEK_SET);
Also I tried...
Code:
fseek(filepathA,-2,SEEK_END);
char test;
test=fgetc(filepathA);
if (test==10)
printf("\nyes, there is a newline there\n");
else
printf("no, there isn't one");