Explain the following functions in a c program fscanf(), fprintf(), fgets(), fputs(), fread(),fwrite(), feof().
fscanf()- This function is used to read data from a file.
Syntax : fscanf(filepointer,”format specifier”,&v1,&v2,….);
Example : fscanf(fp,”%d%d%d”,&a,&b,&c);
fprintf()- this function is used to write data in to a file.
Syntax: fprintf(fileprinter,”format specifier”,v1,v2,…);
Example : fprintf(fp,”%d\t%d\t%d\t”,a,b,c);
fgets()- this function reads s strinf from a file.
Syntax: fgets(string variable,size,filepointer);
Example : fgets(str,40,fp);
fputs()- this function is used to write a string in to a file.
Syntax: fputs(string variable,size,filepointer);
Example : fputs(str,40,fp);
fread()- this function is used to read data into a structure from a file.
Syntax: fread( &structure varable, size of(struct structurevariable), 1, filepointer);
Example : fread(&s,size of(struct s),1,fp);
fwrite()-This function writes a structure in to a file.
Syntax: fwrite(&structure variable,sizeof(struct structure variable),1,filepointer);
Example : fwrite(&s,sizeof(struct s),1,fp);
feof()- this function returns a value true or false. When a file is being read, if there is no more data in the file, then feof() function returns a value true. When a file is being read, if there is more data in the file then the function returns a value false.
Thanks
Mukesh Rajput
Post A Comment:
0 comments: