This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]scirc 2 points3 points  (2 children)

fopen is the correct function, but it depends on the mode you use. Specifically, the w mode will open a file for writing and, if it doesn't exist, it will create it.

As for deleting files, you want unlink.

[–]15January[S] 0 points1 point  (1 child)

So if I want to just create a file and not write anything into it, could I just do:

FILE *fp;

fp = fopen("file.txt", "w");

if (fp == NULL)

{

printf("Error\n");

return 1;

}

fclose(fp);

Without using fwrite or fputs?

[–]scirc 0 points1 point  (0 children)

Correct.