I am trying to create some code where a user inputs the name of a file, and the program then travels a couple of folders up, and then into a separate folder called "Files", finds the file, and echoes it.
void readfile() {
FILE *file;
int c;
char str[30] = "..\\..\\Files";
char temp[30];
printf("Please enter the name of the file\n");
fgets(temp, sizeof (temp), stdin);
strcat(str, temp);
file = fopen(str, "r");
if (file) {
while ((c = getc(file)) != EOF)
putchar(c);
fclose(file);
} else {
printf("File does not exist!");
}
//printf(string);
fclose(file);
}
However, when it tries to open up a file, the program crashes in Netbeans, but it returns the "File does not exist" error in CLion. I am very confused and I cannot pinpoint the problem.