EOF ASCII/HEX code in text files

asciichex-editorhexadecimaljava

As far as know in the end of all files, specially text files, there is a Hex code for EOF or NULL character. And when we want to write a program and read the contents of a text file, we send the read function until we receive that EOF hexcode.

My question : I downloaded some tools to see a hex view of a text file. but I can't see any hex code for EOF(End Of File/NULL) or EOT(End Of Text)


ASCII/Hex code tables :

enter image description here

This is output of Hex viewer tools:

enter image description here


Note : My input file is a text file that its content is "Where is hex code of "EOF"?"

Best Answer

Traditionally, in some contexts there is a End-of-file 'character' - MS-DOS / CMD.EXE uses CTRL+Z - Linux uses CTRL+D

CTRL-Z is code 26, CTRL-D is code 4 in the ASCII table.

These are still in use in situations when you use stdin (in the meaning as applied in "C" programming and general console/tty IO).

e.g.

C:\> copy con myFile.txt
This is text to go into the file.Enter
CTRL+Z
C:\> type myFile.txt
This is text to go into the file.
C:\> 

The very same sequence works in Linux'en with the difference that you start with

$ cat >myFile

and end with CTRL+D, then cat myFile.txt instead of type.

... If you're programming though, you will hardly see any effects of these characters.
I am at this writing not aware of any function call that would stop at these characters.
Read the documentation for your software / library - if there is no statement about the effect of these, then you're not likely to see anything strange happen.

Line endings - CR and LF combinations, code 13 and 10 - is a bit different though, it can get quite messy if you transfer TEXT files from one system to another. unix2dos and dos2unix are shell commands available on Linux'en - for this purpose.

Sample bash session:

$ echo -e "First line\n\x04Second line."
First line
Second line.

$ echo -e "First line\n\x04Second line." | od -t x1z
0000000 46 69 72 73 74 20 6c 69 6e 65 0a 04 53 65 63 6f  >First line..Seco<
0000020 6e 64 20 6c 69 6e 65 2e 0a                       >nd line..<
0000031

$ echo -e "First line\n\x04Second line." | grep line
First line
Second line.

$ cat >myFile.txt
Check this out

$ cat myFile.txt
Check this out

$ 
Related Question