putc - C stdio.h

C examples for stdio.h:putc

Type

function

From


<cstdio>
<stdio.h>

Description

Write character to stream

Prototype

int putc ( int character, FILE * stream );

Parameters

ParameterDescription
character The character.
stream FILE object

Return Value

On success, the character written is returned.

On error, EOF is returned and the error indicator ( ferror) is set.

Example

This example program creates a file called data.txt and writes ABCDEFGHIJKLMNOPQRSTUVWXYZ to it.

Demo Code

#include <stdio.h>

int main ()//w w  w  .j a  v a 2 s  .  co m
{
  FILE * pFile;
  char c;

  pFile=fopen("data.txt","wt");

  for (c = 'A' ; c <= 'Z' ; c++) {
    putc (c , pFile);
  }
  fclose (pFile);
  return 0;
}

Related Tutorials