creating files for writing onlycreating files for


Creating Files for Writing Only

Creating Files for Writing Only : To create a text file for writing only, pass "w" into fopen as the second argument. This example follows along the same lines as the previous:

#include

int main()

{

FILE *file; /* declare a FILE pointer */

file = fopen("data/writing.dat", "w");

/* create a text file for writing */

if(file==NULL)

{

}

else

{

}

}

printf("Error: can't create file.\n");

/* fclose(file); DON'T PASS A NULL POINTER TO fclose !! */

return 1;

printf("File created. Now closing it...\n");

fclose(file);

return 0;

Now, if I went into my data folder, I could see a text file called "writing" was created. However, if my data folder didn't exist, an error would occur.

 

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: creating files for writing onlycreating files for
Reference No:- TGS0305452

Expected delivery within 24 Hours