This program loads 6 words into the array "keywords," then segfaults for some reason. Why does it do this?
Code:
#include<stdlib.h>
int main()
{
char** keywords = (char**) calloc(20, sizeof(char));
int i = 0;
for (i = 0; i < 20; i++)
keywords[i] = (char*) calloc(80, sizeof(char));
char string[] =
{ "Holy cow omg hey haha wow oh jeeze louise lolz." };
char* p = NULL;
char* c = string;
int n = 0;
p = *(keywords + 0);
while (*c)
{
while (!isspace(*c) && *c)
{
*p++ = *c++;
}
*p = '\0';
if (!*c)
break;
c++;
n++;
p = *(keywords + n);
printf("%d\r\n", n);
}
for (n = 0; n < 10; n++)
printf("%s\r\n", keywords[n]);
free(keywords);
return 0;
}