Page 1 of 2
ASCII ReadFile
Posted: Mon Apr 21, 2025 1:16 pm
by rndrei
Why is it withdrawing some strange icons? Hieroglyphs!
Code: Select all
#FILE=1
Define hex_char.c, s.s
If ReadFile(#FILE, "hello.run",#PB_Ascii)
While Eof(#FILE) = 0
hex_char=ReadCharacter(#FILE, #PB_Ascii)
s=Chr(hex_char)
Debug("CHAR=="+s)
Wend
CloseFile(#FILE)
MessageRequester("Information", "cound not read file")
EndIf

Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 1:23 pm
by infratec
Your MessageRequester is at the wrong place.
How can we know what is inside of your file?
If you use #PB_ASCII with ReadFile, you don't need it at ReadCharacter again
ReadCharacter converts the ASCII value already to a readable value,
Try this:
Code: Select all
#FILE = 1
Define char.c
If ReadFile(#FILE, "hello.run", #PB_Ascii)
While Not Eof(#FILE)
char = ReadCharacter(#FILE)
Debug "CHAR==" + char
Wend
CloseFile(#FILE)
Else
MessageRequester("Information", "cound not read file")
EndIf
Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 1:32 pm
by rndrei
It displays the number Char == 17791, but in the ASCII tables there are only 255 characters!
Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 1:37 pm
by infratec
Or you meant:
Code: Select all
#FILE = 1
Define UnsignedByte.a
If ReadFile(#FILE, "hello.run", #PB_Ascii)
While Not Eof(#FILE)
UnsignedByte = ReadAsciiCharacter(#FILE)
Debug "HEX==" + RSet(Hex(UnsignedByte), 2, "0") + " CHAR==" + Chr(UnsignedByte)
Wend
CloseFile(#FILE)
Else
MessageRequester("Information", "cound not read file")
EndIf
Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 1:39 pm
by infratec
Show us what is inside of your file.
I, at least, can not know what is inside.
Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 1:43 pm
by infratec
You are right.
This should work:
Code: Select all
#FILE = 1
Define char.c
If ReadFile(#FILE, "hello.run", #PB_Ascii)
While Not Eof(#FILE)
char = ReadCharacter(#FILE, #PB_Ascii)
Debug "HEX==" + RSet(Hex(char), 2, "0") + " CHAR==" + Chr(char)
Wend
CloseFile(#FILE)
Else
MessageRequester("Information", "cound not read file")
EndIf
And PP 6.21b5 has a bug.
ReadCharacter() does not respect #PB_Ascii from ReadDile()
Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 1:53 pm
by rndrei
File - executable Hello.run ELF for Linux. Anyway, some hieroglyphs give out!?

Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 1:58 pm
by infratec
What do you expect
Which character is value 1, 2 or 0x7F?
Use the code table from the Tools section of the IDE to find out.
Or search for ASCII table in a web search engine.
You are reading a binary file and not an ascii file.
Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 2:24 pm
by rndrei
7F must be.But not a hieroglyph!?
Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 2:35 pm
by infratec
https://www.ascii-code.com/
7F is DEL (which means delete) what should it show?
And in your binary file are also values between 0x80 and 0xFF what do you want to see there?
A 'normal' viewer shows a dot for each not printable character. but this is up to you.
In linux use mc, press F3 on the file and show it in hex.
Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 2:54 pm
by rndrei
I understand, I will understand, it probably still depends on the font!?
Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 3:24 pm
by infratec
No.
A binary file is a binary file. If you want to show it as text, you will always fail.
Re: ASCII ReadFile
Posted: Mon Apr 21, 2025 6:07 pm
by NicTheQuick
rndrei wrote: Mon Apr 21, 2025 2:54 pm
I understand, I will understand, it probably still depends on the font!?
Yes, it also depends on the font. If the font has printable characters for all of the ASCII codes from 0-255 then you would see something different than these squares with hexadezimal numbers in it. But no usual font as these control characters as valid characters.
Re: ASCII ReadFile
Posted: Fri Apr 25, 2025 11:27 am
by rndrei
NicTheQuick wrote: Mon Apr 21, 2025 6:07 pm
rndrei wrote: Mon Apr 21, 2025 2:54 pm
I understand, I will understand, it probably still depends on the font!?
Yes, it also depends on the font. If the font has printable characters for all of the ASCII codes from 0-255 then you would see something different than these squares with hexadezimal numbers in it. But no usual font as these control characters as valid characters.
I didn’t google, maybe you have such a font?
Re: ASCII ReadFile
Posted: Fri Apr 25, 2025 11:30 am
by NicTheQuick
rndrei wrote: Fri Apr 25, 2025 11:27 am
I didn’t google, maybe you have such a font?
I don't have such a font and I don't know why I should need one.
