タイトルが示すように、これは非常に簡単なはずです。理由はわかりませんが、これを実行すると 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]);
}
}