Download presentation
Presentation is loading. Please wait.
Published byLouise Bailey Modified over 9 years ago
1
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming language provides a set of built-in functions to read given input and feed it to the program as per requirement. When we are saying Output that means to display some data on screen, printer or in any file. C programming language provides a set of built-in functions to output the data on the computer screen as well as you can save that data in text or binary files.
2
The Standard Files C is a functional programming language. Therefore, it has no exclusive built-in statements to perform basic input-output operations. To perform these input-output operations, C provides a library of functions. This library is called a standard input-output library. It is denoted by stdio. The header file containing such library functions is called stdio.h. Standard File File Pointer Device Standard input stdin Keyboard Standard output stdout Screen Standard error stderr Your screen
3
The Standard Files There are two type of input output statements. They are: Formatted I/O statements Unformatted I/O statements The formatted I/O statements enable user to specify the type of data and the way in which it should be read in or written out. The unformatted I/O statements do not specify the type of data and the way it should be read or write.
4
I/O Statements There are two type of input output statements. They are: Formatted I/O statements Unformatted I/O statements Input Statements Output Statements Formated Scanf() Printf() Unformated Getchar() Putchar() Gets() Puts()
5
Use of getch(),getche() and getchar() in C
Most of the program is ending with getch(),and so we think that getch() is used to display the output...but it is wrong.It is used to get a single character from the console. Just see the behaviors of various single character input functions in c. getchar() getche() getch() Function : getchar() getchar() is used to get or read the input (i.e a single character) at run time.
6
Use of getch(),getche() and getchar() in C
Declaration: int getchar(void); Example Declaration: char ch; ch = getchar(); Return Value: This function return the character read from the keyboard.
7
Use of getch(),getche() and getchar() in C
Example Program: void main() { char ch; ch = getchar(); printf("Input Char Is :%c",ch); } Program Explanation: Here,declare the variable ch as char data type, and then get a value through getchar()library function and store it in the variable ch.And then,print the value of variable ch. During the program execution, a single character is get or read through the getchar(). The given value is displayed on the screen and the compiler wait for another character to be typed. If you press the enter key/any other characters and then only the given character is printed through the printf function.
8
Use of getch(),getche() and getchar() in C
getche() is used to get a character from console, and echoes to the screen. Declaration: int getche(void); Example Declaration: char ch; ch = getche(); Remarks: getche reads a single character from the keyboard and echoes it to the current text window, using direct video or BIOS. Return Value: This function return the character read from the keyboard.
9
Use of getch(),getche() and getchar() in C
Example Program: void main() { char ch; ch = getche(); printf("Input Char Is :%c",ch); } Program Explanation: Here,declare the variable ch as char data type, and then get a value through getche()library function and store it in the variable ch.And then,print the value of variable ch. During the program execution, a single character is get or read through the getche(). The given value is displayed on the screen and the compiler does not wait for another character to be typed. Then, after wards the character is printed through the printf function.
10
Use of getch(),getche() and getchar() in C
getch() is used to get a character from console but does not echo to the screen. Declaration: int getch(void); Example Declaration: char ch; ch = getch(); (or ) getch(); Remarks: getch reads a single character directly from the keyboard, without echoing to the screen. Return Value: This function return the character read from the keyboard.
11
Use of getch(),getche() and getchar() in C
Example Program: void main() { char ch; ch = getch(); printf("Input Char Is :%c",ch); } Program Explanation: Here,declare the variable ch as char data type, and then get a value through getch() library function and store it in the variable ch.And then,print the value of variable ch. During the program execution, a single character is get or read through the getch(). The given value is not displayed on the screen and the compiler does not wait for another character to be typed.And then,the given character is printed through the printf function.
12
The Standard Files Syntax: gets(string);
The int gets()function reads in every thing you enter from the keyboard until the ENTER key or RETURN is pressed. Everthing, means a string which is a sequence of all printable ASCII charaters. The RETURN key that was pressed at last would not be stored in the charater string. It overcomes the limitation of the scanf() statements with %S option. Syntax: gets(string); Where string is a sequence of characters and is of type char e.g main() { char name[25]; Printf(“ enter your name”); gets(name); }
13
The Standard Files The int putchar(int c) function puts the passed character on the screen and returns the same character. This function puts only single character at a time. Putchar() function putchar(ch_var); Where, ch_var is a character variable which is enclosed within the parentheses. e.g main() { Char ch; putchar(ch); }
14
The Standard Files include<stdio.h> main() { char letter;
letter= getchar(); putchar(letter); }
15
#include <stdio.h> int main( ) { int c;
printf( "Enter a value :"); c = getchar( ); printf( "\nYou entered: "); putchar( c ); return 0; } When the above code is compiled and executed, it waits for you to input some text when you enter a text and press enter then program proceeds and reads only a single character and displays it as follows: Enter a value : this is test You entered: t
16
The Standard Files-Input Functions
Data Type Functions Purpose Char getc() Get character from the keyboard as soon as it is typed,no need to hit enter getche() Similar to getch(),expect echoes the character on the screen fgtechar() Gets the character and choes it on the screen,requires enter key to be hit. getchar() A macro,works similar to fetchar() String Gets() Accepts a string until enter key is hit
17
The Standard Files-Output Functions
Data Type Functions Purpose Char putch() Print a character on the screen fputchar() putchar() A macro,works similar to Putch() String puts() Output a string to the screen
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.