I have a question that might be easy but I\'m having trouble seeing. Is about pr
ID: 3674832 • Letter: I
Question
I have a question that might be easy but I'm having trouble seeing. Is about programming in C. I found this algorithm to skip white spaces with the use of getchar() while((ch=getchar())== ' ')
;
Now, I don't get how this skips white space. What I understand is that getchar reads the character , and then compares it to the white space(they both have a numeric value), then if the character is in fact a white space, the result is true, thus the while loop keeps on reading characters , how come is skipping white spaces? Shouldn't be
while((ch=getchar()) != ' ')
Explanation / Answer
Since the while loop while((ch=getchar())== ' '); has only condition and no body inside it, hence it will do nothing when a space is fed into it. Thus, it skips the spaces.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.