How are you today. I have a question about file name handling :D. My code doesn't want to work it gives me false segmentation.
The idea is to make unique file name and create it if the the file with same name already exists. The first is the exception without file so the for loop starts from 1 instead of 0.
unistd.h is required!
char fileName[15][100];
sprintf(fileName[0],"output.txt");
FILE *output;
for(int i = 1 ;i < 100; i++){
sprintf(fileName[i],"Output%d.txt",i+1);
//File exists
if(!access(fileName[i],F_OK))
{
//Create and open a file
output = fopen(fileName[i], "w");
break;
}
}
I just need to make a try function (like while) till it finds the name which is not taken. I just put the for loop there to have limit to 100.