I'm trying to do a really simple task.
- Check if a file exists
- If not, make it
the files should be named like : M0 M1 M2 and so on.
Here's the code that I've written. It works for M0
after that I get segmentation fault error
:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main (){
unsigned int fileIndex=0;
char* fileName="M0";
FILE* recordFile = NULL;
while((access(fileName,F_OK)!=-1)) {
fileIndex++;
sprintf(fileName,"M%d",fileIndex);
printf("%s\n",fileName);
}
recordFile = fopen(fileName,"wb+");
fclose(recordFile);
return 0;
}
any idea what I'm doing wrong here? thanks in advance!