I'm trying to work on a program that takes a string as an input, parses it into words according to spaces and newline characters, puts each word in its' own space into a char array, then prints the array. However, what I've got so far only prints garbage characters past the first two or so characters.
int main ()
char templist = "This is a bunch of words";
int wordcnt = 0;
tokenptr = strtok(templist, " ");
while (tokenptr != NULL)
if (tokenptr != " ");
*wordlist[wordcnt] = *tokenptr;
if (tokenptr == " ");
tokenptr = strtok(NULL, " ");
for (wordcnt = 0; wordcnt < 100; wordcnt++)
Any idea what I'm doing wrong here?