Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Difference between EOT and EOF

I understand that EOT is ASCII code 4, whereas EOF is encoded as -1 (at least in C). Before I found out that EOF is mapped to -1, I thought it was just a synonym for EOT. Why is EOF mapped to -1 rather than EOT? As far as I can tell, they both do the same thing, which is to terminate a file stream. The only difference I can discern is that EOT also terminates a command in the bash shell. I would like a description of the precise technical differences between these two codes.
by

1 Answer

Amit8z4mc
EOF in the context of C is just something that cannot appear in a file. EOT is an ASCII character that historically signalled the end of a message (and is a special character in UNIX terminals that means end of stream when it appears in user input only), but it CAN appear in files, so using it in C to signal the end of a file would be a terrible idea when reading binary files!

Login / Signup to Answer the Question.