[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


putc

Write a character to a stream.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdio.h>
int putc(int c, FILE *stream);
Parameters:

Parameters for this facility are:

c  
int  
The character to write to a file  
stream  
FILE *  
A pointer to a FILE stream  

Remarks:

The putc() function outputs c to stream and advances stream's file position indicator.

The putc() works identically to the fputc() function, except that it is written as a macro.

If the file is opened in update mode (+) the file cannot be written to and then read from unless the write operation and read operation are separated by an operation that flushes the stream's buffer. This can be done with the fflush() function or one of the file positioning operations (fseek(), fsetpos(), or rewind()).

Return:

putc() returns the character written when successful and return EOF when it fails.

See Also:

"Wide Character and Byte Character Stream Orientation"

"fputc"

"putchar"

Example of putc() usage.:
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	FILE *f;
	static char filename[] = "checkputc";
	static char test[] = "flying fish and quail eggs";
	int i;
	
	// create a new file for output
	if (( f = fopen(filename, "w")) == NULL) {
		printf("Can't open %s.\n", filename);
		exit(1);
	}
	
	// output the test character array
	// one character at a time using putc()
	for (i = 0; test[i] > 0; i++)
		putc(test[i], f);

	// close the file
	fclose(f);

	return 0;
}


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000