Try
#include enum State
{
INSIDE_BLANKS,
INSIDE_WORD
};
void find_longest_word( const char * a, const char ** pps, const char ** ppe);
int main()
{
const char * foo = "alpha beta gamma delta epsilon ";
const char *ps, *pe;
find_longest_word( foo, &ps, &pe);
if ( pe-ps > 0)
{
printf("longest word length = %ld\n", (pe-ps));
while (ps != pe)
{
printf("%c", *ps);
++ps;
}
printf("\n");
}
return 0;
}
void find_longest_word( const char * a, const char ** pps, const char **ppe)
{
const char * ps = a;
const char * pe = a;
*pps = *ppe = a;
enum State state = INSIDE_BLANKS;
while ( *a != '\0')
{
if ( state == INSIDE_BLANKS)
{
if ( *a != ' ')
{
state = INSIDE_WORD;
ps = a;
}
}
else // inside word
{
if ( *a == ' ')
{
pe = a;
if ( pe - ps > *ppe - *pps)
{
*pps = ps;
*ppe = pe;
}
state = INSIDE_BLANKS;
}
}
++a;
}
// special handling of (possible) last word
if ( state == INSIDE_WORD)
{
if ( pe - ps > *pps - *pps)
{
*pps = ps;
*ppe = pe;
}
}
}