As the title indicates, this should be very easy. I don't understand why, but I'm getting a Bus error: 10 when I run this.
This should be so easy! But I can't seem to solve it.... ugh. Please help.
#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]);
}
}