04.06.2013 Views

Dynamic C function reference

Dynamic C function reference

Dynamic C function reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• char getchar( void )<br />

This <strong>function</strong> waits (in an idle loop) for a character to be typed from<br />

the STDIO window in <strong>Dynamic</strong> C. Make sure only one process calls<br />

this <strong>function</strong> at a time.<br />

• int puts( char *s )<br />

This <strong>function</strong> writes the string, identified by pointer s, in the STDIO<br />

window in <strong>Dynamic</strong> C. The STDIO window will interpret any escape<br />

code sequences contained in the string. Make sure only one process<br />

calls this <strong>function</strong> at a time. The <strong>function</strong> returns 1 if successful.<br />

• void putchar( int ch )<br />

Writes a single character (the lower 8 bits of ch) to STDIO. Make sure<br />

only one process calls this <strong>function</strong> at a time.<br />

• int sprintf( char *buffer, char *format, ... )<br />

An analog of standard <strong>function</strong> printf, this <strong>function</strong> takes a “format”<br />

string (*format), and a variable number of value arguments to be<br />

formatted. It formats the arguments, places the formatted string in<br />

*buffer and returns the formatted string length. Make sure that:<br />

1. There are enough arguments after format to fill in the format<br />

parameters in the format string.<br />

2. The types of arguments after format match the format fields in<br />

format.<br />

3. buffer is large enough to hold the longest possible formatted<br />

string.<br />

For example,<br />

sprintf( buffer, ”%s=%x”, ”Variable x”, 256 )<br />

should put the string “Variable x=100” into buffer. This <strong>function</strong> is<br />

reentrant and can be called by processes of different priorities.<br />

The printf <strong>function</strong> is not reentrant. The doprnt <strong>function</strong> implements<br />

printf and sprintf using the character output <strong>function</strong>s<br />

__qen and __qe, respectively. These <strong>function</strong>s accept format strings<br />

and a variable number of parameters whose values are to be printed<br />

according to the format, for example,<br />

printf( “Summary for %s:\n”, person );<br />

printf( “ Age: %d, Income: $%8.2f”, age, income );<br />

The first statement prints a character string. The %s in the format tells<br />

the <strong>function</strong> where and how to print the character string.<br />

The second statement prints two numbers, an integer age and a float<br />

income. The %d in the format tells the <strong>function</strong> where and how to print<br />

the integer: as a decimal string, free-formatted.<br />

24 s General Support Libraries<br />

<strong>Dynamic</strong> C 32 v. 6.x

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!