Page 1 of 1

PostPosted: Thu May 31, 2001 5:50 pm
by maurub
Hey: I have just started to work with PocketC. How can I get into work with interactions with computer with functions like Printf and scanf? Help me.

PostPosted: Sun Jun 03, 2001 6:20 am
by wolfgang
There is no printf or scanf in PocketC.
Use puts (or putsl) instead of printf.
Use gets instead of scanf.
(Refer to the built-in PocketC library functions description to get the exact functionality of these functions).

Wolfgang

PostPosted: Mon Jun 04, 2001 12:43 am
by starfire151
While I understand that the current version of PocketC does not support printf or scanf instructions, they are very useful instructions for creating formatted input and output.

Maybe someone has developed some routines to do these functions???

PostPosted: Wed Jun 06, 2001 3:12 pm
by guy
I've just written a PocketC implementation of printf, sprintf and fprintf. The syntax is nearly the same as the standard library routines:

int count = sprintf(string * result, string format,...) ;
int count = printf(string format,...) ;
int count = fprintf(int handle, string format,...) ;

The format string supports the standard format characters, flags and fields.

The functions use string parameters instead of char* parameters, and sprintf uses a string* to return its value.

Just testing the routines now.

The code contains an interesting fudge to allow variable argument lists to work.

I'll post the files on the pcform page once they're ready.

Hope to do scanf functions next.


Guy

PostPosted: Thu Jun 07, 2001 7:11 am
by guy
Well the functions work, but PocketC breaks the stack on the return from the function.

For some reason the compiler does compile time binding for the stack frame unwind, unlike most other compilers which use a runtime binding to restore the stack to the state that it was in before the call.

This means that the runtime only knows about the fixed parameters for the function, not the trailing variable argument list. It also leaves the argument pointer in the wrong place at the start of the function, so you have to backtrack through the stack to get back to the start of the argument list.

I'll get onto Kevin to see whether this can be changed.


Guy