fputc
int  fputc (int character, FILE * stream);
stdio.h
cplusplus.com

Write character to stream.
Writes character to the current position in the specified stream and increases the file position pointer to the next character.

Parameters.

character
Character to be written. Although it is declared as int, the function converts it to unsigned char before writing it.
stream
pointer to an open file.

Return Value.
  If there are no errors the written character is returned. If an error occurs, EOF is returned.
  Note that when you work with binary files EOF is a valid character and you should use ferror() function to check if an error has occurred.

Portability.
  Defined in ANSI-C.

Example.

/* fputc example: alphabet writer */
#include <stdio.h>

main ()
{
  FILE * pFile;
  char c;

  pFile = fopen ("alphabet.txt","w");
  if (pFile!=NULL)
  {
    for (c = 'A' ; c <= 'Z' ; c++)
    {
      fputc (c , pFile);
    }
    fclose (pFile);
  }
  return 0;
}
  This program creates a file called alphabet.txt and writes ABCDEFGHIJKLMNOPQRSTUVWXYZ on it.

See also.
  fgetc, fread, fwrite, fopen, putc


© The C++ Resources Network, 2000