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


fputc

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 fputc(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 fputc() function writes the character c to stream and advances stream's file position indicator. Although the c argument is an int, it is converted to a char before being written to stream. fputc() is written as a function, not 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()).


NOTE

On embedded/ RTOS systems this function only is implemented for stdin, stdout and stderr files.
Return:

fputc() returns the character written if it is successful, and returns EOF if it fails.

See Also:

"Wide Character and Byte Character Stream Orientation"

"putc"

"putchar"

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

int main(void)
{
	FILE *f;
	int letter;
	
	// create a new file for output
	if (( f = fopen("foofoo", "w")) == NULL) { 
		printf("Can't create file.\n");
		exit(1);
	}

	// output the alphabet to the file one letter
	// at a time
	for (letter = 'A'; letter <= 'Z'; letter++)
		fputc(letter, f);
	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