fprintf and fscanf
#include <stdio.h>
int main()
{
FILE* fp;
char c[16];
fp = fopen("file.txt", "w"); // using write mode
fscanf(stdin, "%s", c); // scan from stdin (standard input)
fprintf(fp, "%s", c); // writing to file
fclose(fp);
fp = fopen("file.txt", "r"); // using read mode
fscanf(fp, "%s", c); // reading from file
fprintf(stdout, "%s", c); // printing to stdout (standard output)
fclose(fp);
return 0;
}Last updated