C - creating new file with custom filename

Viewed 55

I want to create new file with custom filename. I made this function to do this task:

int addfile(char* name)//return 0 if cannot create file
{
    FILE* fn = fopen(name, "r");
    if(fn == NULL)
    {
        return 0;
    }
    fclose(fn);
    addtotab(name, 0);
    return 1;
}

Unfortunately fn variable is always NULLptr so its early return 0. Is any better idea to do this than with fopen?

1 Answers
Related