10

Click here to load reader

Chapter 3 I O Functions

Embed Size (px)

Citation preview

Page 1: Chapter 3 I O Functions

7/23/2019 Chapter 3 I O Functions

http://slidepdf.com/reader/full/chapter-3-i-o-functions 1/10

Vocational crash course on

“ with introduction to embedded

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) 

Chapter 3 : I/O Function

Page 2: Chapter 3 I O Functions

7/23/2019 Chapter 3 I O Functions

http://slidepdf.com/reader/full/chapter-3-i-o-functions 2/10

Time table chart

S.No. Topic Date Total Hours

TH (hrs.) PR(hrs.)

1. Introduction 1 0.5

1. Basic Structure 1 0.5

2. C Fundamentals 4 2

3. I/O Functions 2 1

4. Control statements 4 2

5. Arrays 4 2

6. String handling function 2 1

7. Functions 2 1

8. Structure & Unions 4 2

9. Pointers 4 2

10. Dynamic Memory Allocation 2 1

11. File handling 2 1

12. General Interview Questions 4 2

13. Introduction to Embedded C 4 2

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

Page 3: Chapter 3 I O Functions

7/23/2019 Chapter 3 I O Functions

http://slidepdf.com/reader/full/chapter-3-i-o-functions 3/10

Some Important Commonly Used I/O Functions

• scanf

• getchar

getche/getch

• gets

• printf

• putchar

• puts

Page 4: Chapter 3 I O Functions

7/23/2019 Chapter 3 I O Functions

http://slidepdf.com/reader/full/chapter-3-i-o-functions 4/10

Syntax of scanf function isscanf (“format string”, argument list);

Format String :

• integer (%d)

• float (%f)

• character (%c)

• string (%s)

Variables

Page 5: Chapter 3 I O Functions

7/23/2019 Chapter 3 I O Functions

http://slidepdf.com/reader/full/chapter-3-i-o-functions 5/10

Syntax of getchar() isint 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();

Page 6: Chapter 3 I O Functions

7/23/2019 Chapter 3 I O Functions

http://slidepdf.com/reader/full/chapter-3-i-o-functions 6/10

getchar Vs getche Vs getch

getch() : It reads a character and never wait for Enter key. Justgets processed after getting any key pressed. And it never

echoes the character on screen which u pressed.

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.

Syntax of gets ischar *gets(char *s);

• 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.

gets()

Page 7: Chapter 3 I O Functions

7/23/2019 Chapter 3 I O Functions

http://slidepdf.com/reader/full/chapter-3-i-o-functions 7/10

printfEscape sequence: 

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

Escape

Sequence

Meaning

\n New line

\t Tab

\b Backspace

\a Bell

\o null character

\? print Question Mark

\\ Print Slash

\’  Print Single Quote

\””  Print Double Quote

Conversion specification: • It defines the types of variable which need to be print or scan.• It is preceded by % symbol.

Conversion

character

Meaning

%d Signed decimal integer

%i single decimal integer

%f floating point without exponent

%c single character

%e floating point with exponent

%g either e or f depends uponvariable.

%s String

%x hexadecimal integer

%u unsigned decimal integer

Page 8: Chapter 3 I O Functions

7/23/2019 Chapter 3 I O Functions

http://slidepdf.com/reader/full/chapter-3-i-o-functions 8/10

Page 9: Chapter 3 I O Functions

7/23/2019 Chapter 3 I O Functions

http://slidepdf.com/reader/full/chapter-3-i-o-functions 9/10

putchar

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

Page 10: Chapter 3 I O Functions

7/23/2019 Chapter 3 I O Functions

http://slidepdf.com/reader/full/chapter-3-i-o-functions 10/10

puts

• used to display a string on astandard output device.

• It inserts a newlinecharacter at the end of eachstring it displays.

• It returns non-negative onsuccess, or EOF on failure.