Technical Training
C TutorialsTable of Contents
C Programming - Managing Input and Output Operations
C Programming - Managing Input and Output Operations - Page 2
C Programming - Managing Input and Output Operations - Page 3C Programming - Managing Input and Output Operations
Input Output operations are useful for program that interact with user, take input from the user and print messages. The standard library for input output operations used in C is stdlib. When working with input and output in C there are two important streams: standard input and standard output. Standard input or stdin is a data stream for taking input from devices such as the keyboard. Standard output or stdout is a data stream for sending output to a device such as a monitor console.
To use input and output functionality in your program, you need to include stdio header:
- #include <stdio.h>
Single Character Input and Output
getc is used to accept a character from standard input and is declared as follows:
- int getc(FILE *stream);
You would pass stdin for the stream to get input from the command line. getchar also has the same definition as getc. It is equivalent to getc with stdin as its argument.
- getc(stdin);
fgetc function is recommended for accepting a single character from standard input and is declared as follows:
- int fgetc(FILE *stream);
If the call to fgetc is successful it returns char, otherwise it will return EOF (End of File).
putc is used for sending a single character to standard output and is defined as follows:
- int putc(int c, FILE *stream);
fputc function is recommended instead of putc. fputc syntax is shown here below:
- int fputc(int c, FILE *stream);
Below example demonstrates fgetc and fputc functions.
When fputc is successful, it will return the value, if it fails it will return EOF.
getachar.c:
- #include <stdio.h>
- void main() {
- char ip;
- //prompt for character and get input.
- printf("Type a character and press enter.n");
- ip = fgetc(stdin);
- //write input value back out to standard out.
- fputc(ip, stdout);
- printf("n");
- }
Here is the output I got when typing
"a" for my character:

C Tutorials
- C Programming - An Overview
- C Programming - Data Types : Part 1
- C Programming - Data Types : Part 2
- C Programming - Constants and Identifiers
- C Programming - Operators
- C Programming - Expressions
- C Programming - Managing Input and Output Operations
- C Programming - Decision Making - Branching
- C Programming - Decision Making - Looping
- C Programming - Arrays
- C Programming - Handling of Character String
- C Programming - Functions (Part-I)
- C Programming - Functions (Part-II)
- C Programming - Structures and Unions
- C Programming - Pointers
- C Programming - Dynamic Memory allocation
- C Programming - Linked Lists
- C Doubly Linked Lists
- C Circular Linked Lists
- C Programming - File management in C
- C Language - The Preprocessor
- Call by Value and Call by Reference
- Concept of Pixel in C Graphics
- TSR in C - An Introduction







