A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/putc below:

function

<cstdio>

putc
int putc ( int character, FILE * stream );

Write character to stream

Writes a character to the stream and advances the position indicator.

The character is written at the position indicated by the internal position indicator of the stream, which is then automatically advanced by one.

putc and fputc are equivalent, except that putc may be implemented as a macro in some libraries. See putchar for a similar function that writes directly to stdout.



Parameters
character
The int promotion of the character to be written.
The value is internally converted to an unsigned char when written.
Because some libraries may implement this function as a macro, and this may evaluate the stream expression more than once, this should be an expression without side effects.
stream
Pointer to a FILE object that identifies an output stream.

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* putc example: alphabet writer */
#include <stdio.h>

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

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

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

See also
putchar
Write character to stdout (function)
fputc
Write character to stream (function)
getc
Get character from stream (function)
fwrite
Write block of data to stream (function)
fprintf
Write formatted data to stream (function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4