You are forgetting to take the '
'
that was left in the input after you read n.
You can either change your scanf to: scanf("%d
", &n);
or add a getchar();
right after it.
Also, as mentioned in comments, you are allocating a single char in each array. You should multiply the result sizeof
by the number of letters you want + 1 (remember the
.)
*(x + i) = (char*)malloc(sizeof(char) * DESIRED_LENGTH);
And at the end... you should also free all the pointers (before freeing x), other wise you would have a memory leak:
for (int i = 0; i < n; i++)
free(*(x + i));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…