I am making a program that reads in a file from stdin, does something with it and sends it to stdout.
In the order of things, I have a line in my program:
while((c = getchar()) != EOF){
where cis int.
However, the problem is that I want to use this program for ELF executables. And it seems that there should be a byte that represents EOF for ascii files inside the executable, which leads to truncation (correct me if I am wrong here - this is just my hypothesis).
What is an effective general way to do this? I could dig up ELF documents and then just check what happens at the end. That would be useful, but I think it would be better if I could apply this program to any file.
source
share