The fputc() function is used to write a single character into file. It outputs a character to a stream.
Syntax:
int fputc(int c, FILE *stream)
Example:
#includemain(){ FILE *fp; fp = fopen("file1.txt", "w");//opening file fputc('a',fp);//writing single character into file fclose(fp);//closing file }
file1.txt
The fgetc() function returns a single character from the file. It gets a character from the stream. It returns EOF at the end of file.
Syntax:
int fgetc(FILE *stream)
Example:
#include#include void main(){ FILE *fp; char c; clrscr(); fp=fopen("myfile.txt","r"); while((c=fgetc(fp))!=EOF){ printf("%c",c); } fclose(fp); getch(); }
myfile.txt