ch should be declared as int - otherwise you could not distinguish EOF from the character with the code 0xFFwhile((ch = getchar()) != EOF)
ch should be declared as int - otherwise you could not distinguish EOF from the character with the code 0xFFwhile((ch = getchar()) != EOF)
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Isn't it already int?
Oh, whoops. My bad.
Yeah, getchar() returns an integer, and as vart points out, EOF is (usually) declared as -1. Therefore, if you typed in a 0xFF char (very unlikely unless you're piping input ), it would read as EOF.
Not what you want.
Therefore, declare ch and last_ch as integers.
Do as I say, not as I do . . .
Experimentation is the essence of programming. Just remember to make a backup first.
"I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF
Questions posted by these guidelines are more likely to be answered.
Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.
hmmm. that's big help!
thank you so much!
i just saw that...
i am not really familiar with those character things, i think i will read the book more and spend a few more hours on this.
i'm thinking of making a IS_HAWAIIAN function and test it there, if its hawaiian then return true, if not return false
when it's true it says it's valid
when its false it says it's invalid
but then i won't be able to print the word again...
it's like a mess. oh..
this is my new idea:
in main:
while (num != EOF)
if !is_hawaiian, print invalid
else, print valid
in is_hawaiian:
ch=getchar()
putch(ch)
while white space, ch = getchar
while it is consonant or vowel
if ch and last ch is consonant, false;
if end of word, last isn't vowel, false;
true.
if (ch == EOF) return EOF
if not consonant and not vowel return false;
hope it works.!