0% found this document useful (0 votes)
170 views13 pages

A1581036458 23838 3 2018 Unformatted

The document discusses unformatted input/output functions in C including getchar(), putchar(), getch(), putch(), gets(), and puts(). It provides the syntax and examples of using each function. getchar() and getch() read a single character from standard input while puts() and putchar() output a single character. gets() and puts() are for string input/output, with gets() reading a string and puts() writing one.

Uploaded by

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

A1581036458 23838 3 2018 Unformatted

The document discusses unformatted input/output functions in C including getchar(), putchar(), getch(), putch(), gets(), and puts(). It provides the syntax and examples of using each function. getchar() and getch() read a single character from standard input while puts() and putchar() output a single character. gets() and puts() are for string input/output, with gets() reading a string and puts() writing one.

Uploaded by

Vaibhav Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Outline

• Unformatted Input/Output functions


– getchar()
– putchar()
– getch()
– putch()
– gets()
– puts()
©LPU CSE101 C Programming
Unformatted Functions

• C has three types of I/O functions:


i. Character I/O
ii. String I/O
iii. File I/O

©LPU CSE101 C Programming


getchar()

• This function reads a character-type data from


standard input.
• It reads one character at a time till the user
presses the Syntax
enter key.
Variable-name =
getchar();

Example:
char c;
©LPU CSE101 C Programming
#include<stdio.h>

void main()

char c;

printf(“enter a character”);

c=getchar();

printf(“c = %c ”,c);

}
Enter a character k
c = k

©LPU CSE101 C Programming


putchar()

• This function prints one character on the


screen at a time which is read by standard
input.
Syntax

putchar( variable
name);

Example: char c= ‘c’;


putchar (c);
©LPU CSE101 C Programming
#include<stdio.h>

void main()

char ch;

printf(“enter a character: ”);

scanf(“%c”, ch);

putchar(ch);

}enter a character: r
r

©LPU CSE101 C Programming


getch() & getche()
• These functions read any alphanumeric character
from the standard input device
• The getche() accepts and displays the character.
• The getch() accepts but does not display the
character.

Syntax

getche();

©LPU CSE101 C Programming


#include<stdio.h>
void main()
{
printf(“Enter two alphabets:”);
getche();
getch();
Enter two alphabets a

©LPU CSE101 C Programming


putch()
This function prints any alphanumeric character
taken by the standard input device
#include<stdio.h>
Example:
void main()
{
char ch;
printf(“Press any key to
continue”);
Press any key to continue
You pressed : e
ch = getch();
©LPU CSE101 C Programming
gets()
String I/O
• This function is used for accepting any string.

Syntax
char str[length of string in
number];
gets(str);

©LPU CSE101 C Programming


#include<stdio.h>

void main()

char ch[30];

printf(“Enter the string:”);


Enter the string: Use of data!
gets(ch);
Entered string: Use of data!

printf(“Entered
©LPU CSE101 C Programming string: %s”,
puts()

• This function prints the string or character


array. It is opposite to gets()

Syntax
char str[length of string in
number];
gets(str);
puts(str);

©LPU CSE101 C Programming


#include<stdio.h>

void main()

char ch[30];

printf(“Enter the string:”);

gets(ch);

puts(“Entered string:”);

Enter the string: puts is in use


puts(ch);
Entered string: puts is in use
}

©LPU CSE101 C Programming

You might also like