正如标题所示,这应该很容易。我不明白为什么,但是当我运行它时出现 Bus error: 10。
这应该很容易!但我似乎无法解决它......呃。请帮忙。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main() {
char *string[20];
char buffer[256];
int wordCount = 0;
while ((scanf("%s", buffer) != EOF)) {
printf("%s%d\n", buffer, wordCount);
string[wordCount++] = (char *) malloc (strlen(buffer)+1);
strcpy (string[wordCount], buffer);
}
int j;
printf("There are %d words.\n", wordCount+1);
for (j = 0; j < wordCount; j++)
{
printf("%s\n", string[j]);
}
}