You are on page 1of 16

INPUT AND OUTPUT

STATEMENTS
(Turbo C)
Topics Outline

 Input Statements
 Output Statements
 Format Specifiers
Input Statements

Input Statement
A statement used to input a single
character or a sequence of characters from the
keyboard.
Input Statements (cont.)

Input Functions:
1. getch – a function used to input a single
character from the keyboard without
echoing the character on the monitor.

Syntax: getch();
Example: ch = getch();
Input Statements (cont.)

2. getche – a function used to input a single


character from the keyboard, the character
pressed echoed on the monitor.

Syntax: getche();
Example: ch = getche();
Input Statements (cont.)

3. getchar – a function used to input a single


character from the keyboard, the character
pressed echoed on the monitor, terminated
by pressing the ENTER key.

Syntax: getchar();
Example: ch = getchar();
Input Statements (cont.)

4. gets – a function used to input sequence of


characters from the keyboard, spaces are
accepted, terminated by pressing the ENTER
key.

Syntax: gets();
Example: gets(ch);
Input Statements (cont.)

5. scanf – a function used to input single


character or sequence of characters from
the keyboard, it needs the control string
codes in able to recognize. Spaces are not
accepted upon inputting. Terminated by
pressing spacebar.
Syntax: scanf(“control string codes”, identifier);
Example: scanf(“%d”, &num);
Output Statements

Output Statement
A statement used to display the argument
list or string on the monitor.
Output Statements (cont.)

Output Functions:
1. printf – a function used to display the
argument list on the monitor. It sometimes
needs the control string codes to help
display the remaining argument on the
screen.
Syntax: printf(“control string codes”, argument list);
Example: printf(“Hello %s, you’re %d yrsold”, name, age);
Output Statements (cont.)

Output Functions:
2. putchar – a function used to display the
argument list or string on the monitor. It is
like overwriting a character.

Syntax: putchar();
Example: putchar(tolower (ch));
Output Statements (cont.)

Output Functions:
3. puts – a function used to display the
argument list or string on the monitor. It
does not need the help of the control string
codes.

Syntax: puts();
Example: puts(“hello”);
Format Specifiers

All format specifiers start with a percent


sign (%) and are followed by a single letter
indicating the type of data and how data are to
be formatted.
Format Specifiers (cont.)

List of Commonly Used Format Specifiers:


1. %c – Single character
scanf(“%c”, &ch);
printf(“%c”, ch);
2. %d – Whole number
scanf(“%d”, &num);
printf(“%d”, num);
Format Specifiers (cont.)

3. %f – Number with floating or decimal point


scanf(“%f”, &pesos);
printf(“%f”, pesos);
4. %s – String of characters
scanf(“%s”, &str);
printf(“%s”, str);
THE END

You might also like