Hey,

How do I create a file from a C program? I want to check if the file exists and if it doesnt, then create it. I am using the following code to check if it exists:

filecheck()
{
	b=fopen("password.csv","r+w");
	if(b==NULL)
	{

         // need code for creating a file
       }
}

You can just fopen("file", "w"); to create the file if it doesn't exist.

You can also try checking if a file exists using dirent.h on *nix, check this out:
http://opengroup.org/onlinepubs/007908799/xsh/dirent.h.html

Hope it helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.