I am writing a command line tool in C to control UNDERTALE save files (cuz why not) and I keep getting a segmentation fault whenever I take input from the user.
Here is all my code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#define KILOBYTE 1024
/* The 'm()' is so i know what line the fault happens on */
void m(void) {
printf("X");
}
int main(int argc, char**argv) {
FILE *file;
if (file = fopen("~/.undersave", "r")) {
// Do some code that I haven't written yet
}
else {
char path[KILOBYTE] = "";
printf("It seems that this is your fist time using UNDERSAVE.\nWe just need to go through some quick installation steps.\nWhere do you want your UNDERTALE save folder to be located? >>> ");
m();
fgets(path, KILOBYTE, stdin);
/*
The fault happens here, when it asks me,
i put in the input like normal, but
when I press enter, I get a fault before
it prints 'X'
*/
m();
mkdir(path, 0777);
m();
file = fopen("~/.undersave", "w");
m();
fprintf(file, "%s", path);
m();
fclose(file);
}
return 0;
}