ASCII ReadFile

Just starting out? Need help? Post your questions and find answers here.
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 151
Joined: Thu Dec 28, 2023 9:04 pm

ASCII ReadFile

Post 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
Image
Last edited by rndrei on Mon Apr 21, 2025 1:23 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ASCII ReadFile

Post 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
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 151
Joined: Thu Dec 28, 2023 9:04 pm

Re: ASCII ReadFile

Post by rndrei »

Code: Select all

 Debug "CHAR==" + char
It displays the number Char == 17791, but in the ASCII tables there are only 255 characters!
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ASCII ReadFile

Post 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
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ASCII ReadFile

Post by infratec »

Show us what is inside of your file.

I, at least, can not know what is inside.
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ASCII ReadFile

Post 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()
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 151
Joined: Thu Dec 28, 2023 9:04 pm

Re: ASCII ReadFile

Post by rndrei »

File - executable Hello.run ELF for Linux. Anyway, some hieroglyphs give out!?
Image
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ASCII ReadFile

Post 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.
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 151
Joined: Thu Dec 28, 2023 9:04 pm

Re: ASCII ReadFile

Post by rndrei »

7F must be.But not a hieroglyph!?
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ASCII ReadFile

Post 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.
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 151
Joined: Thu Dec 28, 2023 9:04 pm

Re: ASCII ReadFile

Post by rndrei »

I understand, I will understand, it probably still depends on the font!?
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ASCII ReadFile

Post by infratec »

No.

A binary file is a binary file. If you want to show it as text, you will always fail.
User avatar
NicTheQuick
Addict
Addict
Posts: 1503
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: ASCII ReadFile

Post 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.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 151
Joined: Thu Dec 28, 2023 9:04 pm

Re: ASCII ReadFile

Post 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?
User avatar
NicTheQuick
Addict
Addict
Posts: 1503
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: ASCII ReadFile

Post 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. :D
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply