fprintf and fscanf
just like printf() and scanf() but for file operations!
#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;
}Here, fscanf(stdin,*,*) is as same as scanf(*,*)
Here's an another program to filter even and odd numbers and seperate them,
First, let's generate from 0 to 99,
Now, let's seperate,
Last updated
Was this helpful?