Skip to content

Latest commit

 

History

History
76 lines (52 loc) · 1.3 KB

169_fputc.asciidoc

File metadata and controls

76 lines (52 loc) · 1.3 KB

fputc

NAME

fputc - Write character to stream.

SYNOPSIS
#include <stdio.h>

int fputc(int character, FILE *stream);
DESCRIPTION

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.

SEE ALSO

fgetc, fread, fwrite, fopen, putc

EXAMPLE
link:src/fputc.c[role=include]
OUTPUT
$ gcc -Wall fputc.c
$ ./a.out test.txt
$ cat test.txt
ABCDEFGHIJKLMNOPQRSTUVWXYZ
EXAMPLE
link:src/fputc2.c[role=include]

This program can be used to copy a file (e.g. similar to the Unix 'cp' command, although without parameters).

OUTPUT
$ gcc -Wall fputc2.c
$ echo 'Hello World!' > src.txt
$ cat src.txt
Hello World!
$ ./a.out src.txt dest.txt
$ cat dest.txt
Hello World!