First figure out how to tell the first character of a word.
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char *ch, text[] = "The quick brown fox jumps over the lazy dog.";
int word = 0;
for ( ch = text; *ch; ++ch )
{
if ( isalpha(*ch) )
{
if ( !word )
{
word = 1;
printf("The start of a new word is '%c'\n", *ch);
}
}
else
{
word = 0;
}
}
return 0;
}
/* my output
The start of a new word is 'T'
The start of a new word is 'q'
The start of a new word is 'b'
The start of a new word is 'f'
The start of a new word is 'j'
The start of a new word is 'o'
The start of a new word is 't'
The start of a new word is 'l'
The start of a new word is 'd'
*/
Reputation Points: 2780
Solved Threads: 312
long time no c
Offline 4,790 posts
since Apr 2004