ANDHRA PRADESH
Name :M.Subramanyam
Designation :Senior Lecturer
Branch :Computer Engg.
Institute :Q.Q.Govt.Polytechnic,Hyderabad.
Year/Semester :III Semester
Subject :UNIX & C
Subject Code :CM-304
Topic :Files
Duration :50 Min
Sub Topic :File I/O functions
Teaching Aids :PPTs, Animations
CM304.85 1
Recap
CM304.85 2
Objectives
to know …
CM304.85 3
Character file I/O
CM304.85 4
Character file I/O
Contd..
fputc(): To write a character into the file.
Syntax:int fputc (char, FILE *);
Example
char ch;
FILE *fp;
fputc(ch,fp);
Put the content of the variable ch into the file
pointed by fp.
CM304.85 5
Ex1:
CM304.85 6
Example2
CM304.85 7
Integer file I/O
getw() :To read integer values from the file
Syntax:int getw (FILE *);
Example:
int n;
FILE *fp;
n=getw(fp);
get an integer value from the file pointed by fp
into the variable n.
CM304.85 8
Integer file I/O
CM304.85 9
Example:
CM304.85 10
String File I/O
fgets(): To read a string from a file.
Syntax:
char * fgets(char [], int, FILE *);
Example:
char * fgets(a, n, fp);
a is a character array.
n is no. of characters to be read.
fp-file pointer of type FILE.
CM304.85 11
Example
CM304.85 12
Example
fputs(): To write a string into the file.
Syntax
int fputs(char [], FILE *);
Example:
char a[25];
FILE *fp;
int fputs(a,fp);
a is a character array.
fp-file pointer of type FILE.
Writes string ‘a’ into file.
CM304.85 13
Example
CM304.85 14
Summary
CM304.85 15
Quiz
CM304.85 16
Quiz
CM304.85 17
Quiz
CM304.85 18
Quiz
CM304.85 19
Frequently Asked Questions
CM304.85 20