0% found this document useful (0 votes)
144 views16 pages

Turbo C - Input and Output Statements

This document discusses input and output statements in Turbo C. It covers input functions like getch(), getche(), getchar(), gets(), and scanf() that are used to input single characters or sequences of characters from the keyboard. It also discusses output functions like printf(), putchar(), and puts() that are used to display output on the monitor. Finally, it discusses format specifiers like %c for characters, %d for integers, %f for floating point numbers, and %s for strings that are used with input and output functions.

Uploaded by

Jirou Shiba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views16 pages

Turbo C - Input and Output Statements

This document discusses input and output statements in Turbo C. It covers input functions like getch(), getche(), getchar(), gets(), and scanf() that are used to input single characters or sequences of characters from the keyboard. It also discusses output functions like printf(), putchar(), and puts() that are used to display output on the monitor. Finally, it discusses format specifiers like %c for characters, %d for integers, %f for floating point numbers, and %s for strings that are used with input and output functions.

Uploaded by

Jirou Shiba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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