I have two questions related to the titular exercise, from The C Programming Language. I'm sure that they've both been answered before, so either a direct answer or a link to a previous post (I couldn't find any) would be appreciated.
The exercise itself is to write a C program that removes comments from C code.
I've seen lots of examples of this program, but I can't figure out how to test it. They all use getchar() to "acquire" the code that they're going to edit, but I can't figure out how to tell the program to read another file, rather than to just wait for input from the command line. I tried "./a.out program_to_edit.c", but that didn't work. Alternatively, if there's an easy way to create a string out of blocks of text (rather than one character at a time) like in other languages, that would work too.
This question is a bit more general. I'm confused about how escape characters work when reading C source code with getchar(). If I'm viewing a .c file in TextEdit, I see "\t", but if I compiled it and printed that out, it would come out as a tab character. Does that mean that the .c file contains '\\' and 't' and the compiler combines them, or is it something else entirely? What will getchar() return if I use it to read through that file?
Thanks.
./a.out < program_to_edit
.