A RetroSearch Logo

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

Search Query:

Showing content from https://cplusplus.com/reference/cstdio/getchar/ below:

function

<cstdio>

getchar

Get character from stdin

Returns the next character from the standard input (stdin).

It is equivalent to calling getc with stdin as argument.



Parameters (none)

Return Value On success, the character read is returned (promoted to an int value).
The return type is int to accommodate for the special value EOF, which indicates failure:
If the standard input was at the end-of-file, the function returns EOF and sets the eof indicator (feof) of stdin.
If some other reading error happens, the function also returns EOF, but sets its error indicator (ferror) instead.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
/* getchar example : typewriter */
#include <stdio.h>

int main ()
{
  int c;
  puts ("Enter text. Include a dot ('.') in a sentence to exit:");
  do {
    c=getchar();
    putchar (c);
  } while (c != '.');
  return 0;
}

A simple typewriter. Every sentence is echoed once ENTER has been pressed until a dot (.) is included in the text.

See also
getc
Get character from stream (function)
putchar
Write character to stdout (function)
scanf
Read formatted data from stdin (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