I'm trying to create a function that checks if a file exists, if it does then it will open it up in order to update it, and if it doesn't exist it will create a new one.
void readFunc(void) {
FILE *input;
char filename[N];
printf("Write textfile: ");
scanf("%s", filename);
if(input == NULL) {
printf("\nFile doesn't exist. Creating a new one!\n\n");
input = fopen(filename, "w+");
} else {
printf("\nFile exists!\n\n");
input = fopen(filename, "r+");
}
}
This is what my code looks like now. I know it might be very wrong but I would like to know how to think in order for it to work.
I will insert pointers later in order for it to work well with the main function.