fputc - C stdio.h

C examples for stdio.h:fputc

Type

function

From


<cstdio>
<stdio.h>

Description

Write character to stream

Prototype

int fputc ( int character, FILE * stream );

Parameters

ParameterDescription
character The character to be written.
stream a FILE object.

Return Value

On success, the character written is returned.

If a writing error occurs, EOF is returned and the error indicator (ferror) is set.

Example

The following code creates a file called data.txt and writes ABCDEFGHIJKLMNOPQRSTUVWXYZ to it.

Demo Code


#include <stdio.h>

int main ()//from   www .jav a  2  s.c o m
{
  FILE * pFile;
  char c;

  pFile = fopen ("data.txt","w");
  if (pFile!=NULL) {
    for (c = 'A' ; c <= 'Z' ; c++)
      fputc ( c , pFile );

    fclose (pFile);
  }
  return 0;
}

Related Tutorials