Unifix knowledge database - The original one

Dashboard - News - Search - List - About - Admin


Why i dont code C , Kernighan and Ritchie style

Author:mike - Mon Feb 6 22:35:09 2006

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!
Copyright(c) Unifix.org 2002-2011


Dashboard - News - Search - List - About - Admin
 
Powered by Mikjaer Consulting Solutions - Hosted by Specialhosting.dk