I'd like to print ALL characters stored in a string including escape sequences.
I know printing escape sequences will just print blank so I've made some modifications which first checks whether the character is a specific escape sequence then print '\\escape sequence' so I can visualize it.
Below is a portion of my c-code and output run in linux gcc environment.
I've found out '\n' is printable with my code but comparing with the output below (no escape sequence check) there is something missing which I don't know.
The text file was created in Windows so I assume for every end of the line there exists characters '\r\n' but '\r' doesn't seem to be there.
What am I missing ?
char c;
while ((c = fgetc(fp)) != EOF) {
if (c == '\n') { printf("\\n\n"); }
else if (c == '\r') { printf("\\r\n"); }
else if (c == '\0') { printf("null\n"); }
else { printf("%c\n", c); }
}
printf("\n----------------\n");
fseek(fp, 0, SEEK_SET);
while ((c = fgetc(fp)) != EOF) {
printf("%c\n", c);
}
contents of the text file:
1
2
blank
blank
3
4
Output Result:
Output Result [CoffeeTableEspresso] asked for: