I had to write a simple database (console application) in C: You could input gender, name and adress of people and the data would be saved in an array of structs called 'Person'. You could then also display all entries or delete entries again. So far so good.
Now I have to add functions to save the data into a .csv file and read from it again. However, the function fopen()
always returns a NULL
-pointer, so I can't even get to the reading or writing part. Below is my code. I hope you can tell me why not even this first step is working. I'm rapidly losing any confidence I had in my C abilities.
void save(Person persons[]) {
char name[LEN];
printf("File Name: ");
fgets(name, LEN, stdin);
fflush(stdin);
name[strlen(name)] = '\0';
FILE *file = fopen(name, "wx");
if (!file) {
printf("The file couldn't be created.\n\n");
}
}