Forum > Beginners

The function ReadLn(file, str) ignores tab characters.

(1/2) > >>

Galmer:
Hi all!
Tell me why the ReadLn function ignores tab characters when reading from a file?

I have a file in which the data is separated by tab characters, but when this function reads from the file, no tab characters are found. At the same time, if you use the Read(file, char) function, the tab character (#10) is detected.

If nothing can be done about this, can someone tell me how to create strings character by character? I'm just new to Pascal, before this I programmed more in C.

Thaddy:
The TAB character is #9, NOT #10: that is a linefeed (LF).(that is the same in C, btw)
It ignores the linefeed, because it is not needed for readln, depending on platform. You can use the predefined constant sLineBreak for cross-platform use.(or sLineEnding, which is the same)
These resolve to #13#10 on Windows and DOS and family and just #10 on Unix. On the windows/dos family readln does not have to read the #10 part if #13 is encountered. #13 means CR, a carriage return, again same in C.

Things change a bit when you are misusing strings to read binary data which is a common mistake that people coming from C make.
you can not assume * char is binary data, since char refers to a Pascal char, not a byte. If that is what you need report back and I write you a simple example on how to handle binary data that assumes * char in C.

Galmer:

--- Quote from: Thaddy on April 07, 2024, 01:08:54 pm ---
--- End quote ---
Thank you very much, you helped me a lot! But now I'm ashamed of my stupidity. Spending so much time simply by mixing up the number of tab characters...

Please tell me why the search for '\t' doesn't work then?

Thaddy:
Because \t uses \ which is an escape character: it means that a C compiler needs to interpret the literal value, and not 't'. In pascal you already escape the character by using the # notation. Pascal is not aware of C escapes, only Pascal escapes. So \t translates to #9 in Pascal. Both translate to 9 in the ASCII table. Not to '9'. Neither C nor Pascal store \ or #, just the value 09 as a byte value.
Escape characters are not part of the binary data and usually not stored unless stored as string.

Galmer:

--- Quote from: Thaddy on April 07, 2024, 01:34:29 pm ---
--- End quote ---
Thanks again!

Should I delete this topic if the problem is my stupid mistake?
Will it make it difficult to search the forum?

Navigation

[0] Message Index

[#] Next page

Go to full version