Last active
March 27, 2018 01:36
-
-
Save kmsheng/f3a7f38972f943c6bbdba3b4f82f418d to your computer and use it in GitHub Desktop.
An example of how to write file in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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