cant write text file in c -
im trying learn c, i'm using tutorialspoint, , function give me doesn't on computer, function is:
#include <stdio.h> int main (){ file *fp; fp = fopen("/tmp/test.txt", "w+"); fprintf(fp, "this testing fprintf...\n"); fputs("this testing fputs...\n", fp); fclose(fp); }
am missing something?
it introduce error checking file streams
do
fp = fopen("test.txt", "w+"); /* * try creating file in same folder start */ if(fp!=null) { fprintf(fp, "this testing fprintf...\n"); fputs("this testing fputs...\n", fp); } else { /* there multiple reasons can't open file : * don't have permission open * parent directory doesn't exist , on. */ printf("can't open file write\n"); } fclose(fp);
Comments
Post a Comment