October 22, 2024
Chicago 12, Melborne City, USA
C#

C and getchar() behaviour


I am pretty new to coding and I read the K&R book. As I try to solve proposed exercises, I face my first problem (1-13).

Why with, the code below I get tabul populated

while ((c = getchar()) != EOF) {
    if (c == ' ' || c =='\n' || c == '\t') {
        ++tabul[lw];
        lw = 0;
    } 
    else
        ++lw;
}

and not with

while ((c = getchar()) != EOF) {
    if (c != ' ' || c !='\n' || c != '\t') {
        ++lw;
    } else {
        ++tabul[lw];
        lw = 0;
    }
}

?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video