Try the following:
The 'valid' integer is also being used as a counter of all alpha characters found in the string. Spaces are ignored. Any non-alpha character ends the while loop and displays the error message.
while ( string[idx] != '\0' )
if ( !isalpha(string[ndx]) )
if ( !isspace(string[idx] )
printf("\nThe length of the sentence is %i", valid)
(My C is a bit rusty, but this looks about right.)
Did your code just change or did mine????