Monday, April 1, 2013

getchar() and putchar()

A simple program that reads one character from the keyboard and prints it out on the screen.

/* getchar() and putchar() */
#include <stdio.h> int main (void) { char c; printf ("Enter a character: "); /* getchar() gets a single character from the keyboard */ c = getchar(); printf ("The character is: "); /* putchar() prints a single character on the screen */ putchar (c); return (0); }
Legend: preprocessor directives | variable declarations | main program | helper functions | user-defined structures | comments
Enter a character: @
The character is: @

No comments:

Post a Comment