1. String I/o operations:
The functions used to handlestring i/o operationsare
fgets() and fputs()
fgets()
This function is used to read a set of characters as a string
from a given file and copies the string to a given memory
location in an array.
The general format is
Fgets(sptr,n,fptr)
Where ‘sptr’ is a pointerto the location to receive the
string ‘n’ is the count of the maximum number of
characters to be in the string and the fptr is the file pointer
of the file to be read.
The fgets() function reads n-1 characters. The function
appendsa null characterto the last characterread and then
stored the string at the specified location.
fputs()
This is used to write a string to a given file
The general format is fputs(sptr,fptr)
2. Where sptr is a pointer to the string to be written and fptr
is a file pointerto the file.
The fputs() function is normally used to copy strings from
one file to another.
Getw()
This function is used to read an integer value from a given
file. It returns the next integer from the input file.
The general format is getw(fptr)
Where fptr is a pointerto a file to receive an integer value
Putw()
Is used to write an integer on to the specified file.
Syntax is putw(w,fptr)
Where w is an integer value to be written on a given file
and fptr is a file pointerto a given file.
Formatted I/o operations:
Fscanf() and fprintf() functions are used to access and
process the formatted data
Fscanf()
Is used to read a formatted data from a specified file
This function works in the same way as scanf() function
3. But it has one more parameter placed as first which is a
data file pointer. This is user defined input file.
The general syntax is
Fscanf(file pointer,”control string”,argument list);
Where controlstring contains the specified for the items
in the arguments such as %d %f etc.The argument list is
the variable parameters list to be read from the specified
file.
Eg: fscanf(ptr,”%s%d”,name,&num);