Untested sample. You should read up on each of these functions. To make sure you do, I'm deliberately not looking up the order of parameters as I normally should an am quite likely guessing wrong on some of the calls.
/* Untested Sample of "What it kinda should maybe look like" */
char buf[BUFSIZ];
fgets(stdin,buf); /*read a line*/
int i;
char *p;
for (p=buf,i=0; p+=strspn(p," .,"); i++) /*count delimiters*/;
char **words;
words = malloc(i+1 * sizeof(char *));
for (i=0, words[0]=strdup(p=strtok(buf," .,"); words[++i]=strdup(p=strtok(NULL," .,"));) /**/;
words[++i]=NULL;
BUFSIZ should give you a pretty huge buffer (enough for any reasonable textfile). Scan the buffer and count delimiters to give a good guess at the max number of words we'll find. Allocate an array of char pointers. Fill the array with strdup
copies of the return values from a sequence of calls to strtok
. The first call to strtok
passes the string as the first argument. Calls after that pass NULL as the first argument which means "keep using the same string". Also I'm not sure about that second loop termination. Treat this as pseudocode. :)
Edit: If you've got the word in a string, strlen
will give you the length (not counting the terminating nul byte).