Skip to content

Instantly share code, notes, and snippets.

@kmsheng
Last active March 27, 2018 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmsheng/f3a7f38972f943c6bbdba3b4f82f418d to your computer and use it in GitHub Desktop.
Save kmsheng/f3a7f38972f943c6bbdba3b4f82f418d to your computer and use it in GitHub Desktop.
An example of how to write file in C
#include <stdio.h>
#include <string.h>
int main () {
int ret;
FILE *fp;
char filename[] = "/home/user1/file.txt";
fp = fopen(filename, "w");
if (NULL == fp) {
printf("Could not open file for writing\n");
return 1;
}
fprintf(fp, "Here's some content for file.txt");
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment