Sie sind auf Seite 1von 10

Vocational crash course on

C with introduction to embedded C


Chapter 3 : I/O Function

Course instructor :
Prof. Kumar Anand Singh
(Asst. Professor, EC, MEFGI)
Course assistances:
Prof. Hetal Dave
(Asst. Professor, EC, MEFGI)
Mr. Saumil Vora
(Student, PG-VLSI, 1st year)

Time table chart


S.No.

Topic

Date

Total Hours
TH (hrs.)

PR(hrs.)

1.

Introduction

0.5

1.

Basic Structure

0.5

2.

C Fundamentals

3.

I/O Functions

4.

Control statements

5.

Arrays

6.

String handling function

7.

Functions

8.

Structure & Unions

9.

Pointers

10.

Dynamic Memory Allocation

11.

File handling

12.

General Interview Questions

13.

Introduction to Embedded C

40

20

TOTAL (12 days,10th Dec 2014 to 23rd Dec 2014)

Some Important & Commonly Used I/O Functions


scanf
getchar
getche/getch
gets
printf
putchar
puts

Syntax of scanf function is


scanf (format string, argument list);

Format String :
integer (%d)
float (%f)
character (%c)
string (%s)

Variables

Syntax of getchar() is
int getchar(void);

It returns the unsigned char.


If end-of-file or an error is encountered getchar() functions return EOF.

For example:
char a;
a= getchar();

gets()
getchar Vs getche Vs getch

It is used to scan a line of text from a standard input.

The gets() function will be terminated by a newline character.


The newline character won't be included as part of the string.

getch() : It reads a character and never wait for Enter key. Just
gets processed after getting any key pressed. And it never
echoes the character on screen which u pressed.
Syntax of gets is
char *gets(char *s);

getche() : it works same as getch() but it echoes on screen.


getchar() : It works differently from others two. Whenever
you are pressing any key then the these are kept in Buffer.
After hitting enter the first character gets processed. And it
obviously echoes on the screen.

printf
Escape sequence:
Escape sequence is a pair of character which performs specific operations.

Conversion specification:

It defines the types of variable which need to be print or scan.


It is preceded by % symbol.

Escape
Sequence

Meaning

\n

New line

\t

Tab

\b

Backspace

\a

Bell

\o

null character

\?

print Question Mark

\\

Conversion Meaning
character
%d

Signed decimal integer

%i

single decimal integer

%f

floating point without exponent

%c

single character

%e

floating point with exponent

%g

Print Slash

either e or f depends upon


variable.

%s

String

Print Single Quote

%x

hexadecimal integer

Print Double Quote

%u

unsigned decimal integer

putchar
putchar function displays a single character on the screen.
prototype:
int putchar(int c);

puts
used to display a string on a
standard output device.
It inserts a newline
character at the end of each
string it displays.
It returns non-negative on
success, or EOF on failure.

Das könnte Ihnen auch gefallen