gtpc2m5h | C/C++ Language Support User's Guide |
This function writes a character to a stream.
Format
#include <stdio.h> int putc(int c, FILE *stream); int putchar(int c);
This function converts c to unsigned char and then writes c to the output stream at the current position. The putchar function is identical to:
putc(c, stdout);
These functions are also available as macros. For better performance use the macro forms rather than the functional forms.
By default, if the stdio.h header file is included, the macro is called. Therefore, the arguments should not be expressions that cause the values of variables to change.
You can access the actual function by using one of the following methods:
The putc and putchar functions have the same restriction as any write operation for a read immediately following a write, or a write immediately following a read. Between a write and a subsequent read, there must be an intervening flush or reposition. Between a read and a subsequent write, there must be an intervening reposition unless an end-of-file (EOF) has been reached.
Normal Return
The putc and putchar functions return the character that is written.
Error Return
A return value of EOF indicates an error.
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Examples
The following example writes the contents of a buffer to a data stream. The body of the for statement is null because the example carries out the writing operation in the test expression.
#include <stdio.h> #define LENGTH 80 int main(void) { FILE *stream = stdout; int i, ch; char buffer[]= "Hello world"; /* This could be replaced by using the fwrite routine */ for ( i = 0; (i < strlen(buffer)) && ((ch = putc(buffer[i], stream) ++i); }
Output
Hello world
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.