Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote