Input and Output Statements - 1
Input and Output Statements - 1
Output
I/O of string
• gets( string)
• puts(string
General input(scanf)
• to read any type of data such as integer (%d), character
(%c) and float (%f)
• Syntax of scanf
– scanf(“control_string”, arg1, arg2….., argn);
– Each argument combination of ampersand(&)sign and variable
name
• Control_string
– Format: %wp
– %- conversion character, w-width of input value(optional), p
data type of character
• Control string may be continuous or separated by blank
space, tabs etc. If this character used, they are read by
computer but will be ignored.
scanf
Some invalid input statements
General output (printf function)
• Used to print any type of data such as
numeric, single character and string
• General form:
– printf(“control_string”, arg1,arg2… argn);
• It may be noted that the arguments of printf
do not represent memory address and hence
no ampersand(&) sign required
Example printf
Specifier input single character (%c)
• Reads single character
Input : abcde
output
output
Input %s
• Used to read string which is an array of characters
• General form: %ws(w represent length of the string)
• This specification terminates reading at the counter of a blank
space or new line
• the string name not requires any ampersand before it in scanf
Input1 : Abu
Input2: bakar
I/O %c and %s
Input: in the waterfall