OiO.lk Blog C# C and getchar() behaviour
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

Exit mobile version