Input and output from file: There are many methods to input and output from file these are:
1. putc(): putc function is used to write a character in a file.
Syntax: putc(char-variable,file-pointer);
2. getc(): getc function is used to read a character from a file.
Syntax: char-variable = getc(file-pointer);
3. putw(): putw is same just like the putc function but it used to write an integer on a file.
Syntax: putw(integer,fp);
4. getw(): getw is used to read an integer from a file.
Syntax: getw(file-pointer);
5. fprintf(): fprint function is just like the printf() function in c. But this function is used in the files and we can write the data of different type in a file and using single function.
Syntax: fprintf(file-pointer,”control string”,variable-list);
In the above syntax control string means the format of data.
e.g: fprintf(fptr,”%d %s %f”, roll_num, name, marks);
6. fscanf():fscanf function is just like the fscanf() function in c. But this function is used in the files and we can read the data of different type from a file and using single function.
Syntax: fscanf(file-pointer,”control string”,variable-list);
e.g: fscanf(fptr,”%d %s %f”, roll_num, name, marks);