Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Don't you mean

    char c = getchar();
    while (c != EOF) {
        c = getchar();
        …
    }
?

Which not only reads badly but requires writing the "producer" twice. Though alternatively you could:

    while (1) {
        c = getchar();
        if (c == EOF) { break; }
        ...
    }


    char c;
    do {
        c = getchar();
    } while (c != EOF);


This is worse, in most cases as you normally want to do something to c after you have read it, forcing you to re-check the condition

    int c; //a char can't represent EOF
    do {
        c = getchar();
        if (c != EOF) {
           //do stuff
        }
    } while (c != EOF);




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: