How would I convert the following while
loop into a proper do-while
without double counting the first time?
void ctype()
{
char c;
while ((c = getchar()) != '.')
printf("'%c' is %s a letter.\n", c, isalpha(c)? "indeed" : "not");
printf("'%c' is %s a letter.\n", c, isalpha(c)? "indeed" : "not");
}
What I have thus far is:
void ctype()
// Print the letters up through the period, but quit on the period
{
char c = getchar();
do {
printf("'%c' is %s a letter.\n", c, isalpha(c)? "indeed" : "not");
} while ((c = getchar()) != '.')
}
But this double-getchar
's on the first item. What would be the proper way to do this? It's almost like I want the equivalent of a post-increment on the getchar()
in the while loop.
Sample input/ouput of the while
loop, which is currently correct:
$ run
.
'.' is not a letter.
$ run
Hello.
'H' is indeed a letter.
'e' is indeed a letter.
'l' is indeed a letter.
'l' is indeed a letter.
'o' is indeed a letter.
'.' is not a letter.