cplusplus.com > reference > cstdio > fputc
fputc
<stdio.h>
cplusplus.com
int  fputc (int character, FILE * stream);

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.

Portability.
  Defined in ANSI-C.

Example.

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

int 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