Calling fprintf_, fread_ from PB linux

Linux specific forum
gkaizer
User
User
Posts: 40
Joined: Fri Oct 31, 2003 2:57 pm
Location: Italy

Calling fprintf_, fread_ from PB linux

Post by gkaizer »

i know that PB on linux supports these two API, but i can't figure out how to call them to write to stdout and read from stdin resp...
any idea?

i tryed

Code: Select all

#stdout = 2
fprintf_(#stdout,"message")
but no way... i know fprintf_ and fread_ and others receive an argument of type FILE, but i don't know how to tell them to pass stdin, stdout or stderr...
another question...anybody knows whether i can declare a variable being of type FILE, or do i have to put

Code: Select all

Structure FILE
	_ptr.s
	_cnt.l
	_base.s
	_flag.l
	_file.l
	_charbuf.l
	_bufsiz.l
	_tmpfname.s
EndStructure
before declaring the variable of that type?

thanks
--:: Gkaizer ::--
Using PB 3.92 on WinXP SP2 and 3.91 on Mandrake Linux 10.0
User avatar
wichtel
User
User
Posts: 71
Joined: Fri May 02, 2003 11:14 am
Location: Germany
Contact:

Post by wichtel »

How about that:

Code: Select all

Global stdout.l,stdin.l
Global nl.s
nl=Chr(13)+Chr(10)


stdout=fopen_("/dev/stdout","w")
stdin=fopen_("/dev/stdin","r")

buffer.s=Space(10)
size.l=0

fread_(@buffer,10,1,stdin)

;like this 
fprintf_(stdout,"Hello World %1$d"+nl,2004)

;or like this
printf_(buffer+" Number %1$d"+nl,1234)

fclose_(stdout)
printf writes to stdout anyway.
you first need a format string and then the values

fread reads 1 block of 10 characters from stdin.
To test it compile the source on linux and enter e.g.:
cat /etc/hosts | ./purebasic.exe

Hope that helps.
PB 5.40 LTS, W7,8,10 64bit and Mint x64
gkaizer
User
User
Posts: 40
Joined: Fri Oct 31, 2003 2:57 pm
Location: Italy

Post by gkaizer »

:lol: thank you very much indeed
cheers
--:: Gkaizer ::--
Using PB 3.92 on WinXP SP2 and 3.91 on Mandrake Linux 10.0
Post Reply