Skip to content

Instantly share code, notes, and snippets.

@webgtx
Created March 14, 2022 10:40
Show Gist options
  • Save webgtx/1f49d4fad395334d3b7897dfd25a9f3b to your computer and use it in GitHub Desktop.
Save webgtx/1f49d4fad395334d3b7897dfd25a9f3b to your computer and use it in GitHub Desktop.
How to use file system in C
void wrt_file(char * dat, char * filename) {
FILE *file = fopen(filename, "w");
fprintf(file, dat);
fclose(file);
}
void rd_file(char * filename, char * file_str) {
int c;
int idx = 0;
FILE *file;
printf("filename: %s\n", filename);
file = fopen(filename, "r");
if (file) {
while ((c = getc(file)) != EOF) {
file_str[idx] = c;
idx++;
}
fclose(file);
}
printf("filedat: %s\n", file_str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment