use the lower-level open() call instead, passing the O_WRONLY | O_CREAT | O_EXCL flags:
O_CREAT create file if it does not exist
O_EXCL error if create and file exists
The following opens the file with exclusive create, then associates the returned file descriptor
with a buffered stream:
FILE *fileP = NULL;
int fd = -1;
if ((fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, mode)) != -1) {
fileP = fdopen(fd, "w")
}
Main Topics
Browse All Topics





by: darkrainPosted on 2004-01-25 at 16:51:03ID: 10198042
Try this way
FILE *TEST;
TEST = fopen(filename ,"r");
if (TEST == NULL)
{
TEST = fopen(filename ,"w");
iCloseSucess = fclose(infClubber);
if (iCloseSucess ==0)
{
printf("\File Created");
}
else
{
printf("file already exists");
}
}
a bit simple but it might help