Page 1 of 1

Calling fprintf_, fread_ from PB linux

Posted: Fri Sep 24, 2004 3:00 pm
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

Posted: Wed Sep 29, 2004 2:56 pm
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.

Posted: Thu Sep 30, 2004 9:24 am
by gkaizer
:lol: thank you very much indeed
cheers