Reputation: 3762
Why is fscanf in this code giving me a 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++;
}
Upvotes: 1
Views: 72
Reputation: 103
Because you didn't allocate memory for your words[i]. They are just pointers point to random memory addresses.
Upvotes: 1