Standard Library Functions in C

adplus-dvertising
putc() Function
Previous Home Next

Description

The C library function, The putc() function writes the character ch to the specified stream at the current file position and then advance the file position indicator. Even though the ch is declared to be an int, it is converted by putc() into an unsigned char.

Declaration

Following is the declaration for putc() function.

int putc(int char, FILE *stream)

Parameters

char - This is the character to be written on stream.

stream - The stream to write to.

Return Value

The putc function returns the character written in stream, on success. If an error occurs, EOF is returned and the error indicator is set.

Example

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

int main ()
{
  FILE * pFile;
  char c;

  pFile=fopen("abc.txt","wt");
  for (c = 'A' ; c <= 'Z' ; c++) {
    putc (c , pFile);
    }
  fclose (pFile);
  return 0;
}
Previous Home Next