Why i dont code C , Kernighan and Ritchie style

Page 14. "The C Programming Language" By Brian W. Kernighan and Dennis M. Ritchie  1978 a simple program to read characters from STDIN:

#define EOF -1

main()
{
        int c;

        c = getchar();
        while (c != EOF)
        {
                putchar(c);
                c = getchar();
        }
}

My logic mind prefers the following:

#define EOF -1
int main(void)
{
        int c;
        for (c=0; c!= EOF; c=getchar()) { putchar(c);}
}

Simple, logic and straightforward. Who wouldnt understand that?

 ... Now with CC-Compliance!
Dette indlæg blev udgivet i Knowledge Base. Bogmærk permalinket.

Skriv et svar