[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


getchar

Get the next character from stdin.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdio.h>
int getchar(void);
Parameters:

None

Remarks:

The getchar() function reads a character from the stdin stream.


NOTE

Getchar() is implemented as getc(stdin) and as such getchar's return may be delayed or optimized out of program order if stdin is buffered. For most implementations stdin is line buffered.
Return:

getchar() returns the value of the next character from stdin as an int if it is successful. getchar() returns EOF if it reaches an end-of-file or an error occurs.

See also::

"Wide Character and Byte Character Stream Orientation"

"fgetc"

"getc"

"putchar"

Example of getchar() usage:
#include <stdio.h>

int main(void)
{
	int c;
	
	printf("Enter characters to echo, * to quit.\n");

	// characters entered from the console are echoed
	// to it until a * character is read
	while ( (c = getchar()) != '*')
		putchar(c);

	printf("\nDone!\n");

	return 0;
}

Output:
Enter characters to echo, * to quit.
I'm experiencing deja-vu *
I'm experiencing deja-vu
Done!


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000