c - fscanf segfault reading into an array -
why fscanf in code giving me segfault?
int main(int argc, char *argv[]) { file *file = fopen(argv[1], "r"); int n = atoi(argv[2]); char *words[n]; int i=0; while ((fscanf(file, "%s ", &words[i])) != eof) i++; }
because didn't allocate memory words[i]. pointers point random memory addresses.
Comments
Post a Comment