I have a code and can't figure out why it's crashing (segmentation fault) I know from past posts that it has something to do with unaccessable memory (I think), but I initialized my "input" variable.
#include <stdio.h>
#include <stdlib.h>
char *getInfo() {
char input[1000];
scanf("%s", input);
return input;
}
int main() {
char *x;
x = getInfo();
printf("%s\n", x);
return 0;
}
When I run and backtrace the program inside gdb, it says (among other things) "... in main () at error.c:11" When I break at line 11 after giving input ("bark") try to print the variables, print input gives me '\000 x29' and print x gives me 0x0. I know that 0x0 means that it's null, and I think \000 also means null, but I don't get why., when I scaf'ed input, shouldn't the null be replaced?