Thread: a website for simple c programs for beginners

  1. #1

    Lightbulb a website for simple c programs for beginners

    There is a site which has simple c programs for beginners.
    Check the site and let me know what you think about it.
    Please feel free to give your feedback about this site.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    It's not bad, although I suggest using something more portable than the clrscr() function to clear the screen. It's not included in all compilers.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Just browsing the first few I wouldn't recommend this to people just learning the language...or anyone for that matter, it uses both unportable and undefined constructs as well as some bad style.
    Here are just a few things I saw:
    1. main()
    This is nonstandard, the ISO C standard defines main to be declared as either int main( void ) or int main( int argc, char **argv ).
    Anything else is just wrong.

    2. clrscr()
    Not everyone has a compiler that defines this function, conio.h is nonstandard and programs using it that are ported to other compilers will flag errors. Learners shouldn't be thrown into that kind of debugging early on.

    3. getch()
    See above comment on clrscr(). I don't recommend getch at all unless you write it yourself, getchar() does the same thing and is a standard function so it will work regardless of the compiler or system.

    4. fflush( stdin );
    This is undefined, anyone who wants to write good programs should think of undefined as illegal. You can't flush stdin, this was stated explicitly in the ISO C standard. A better way to eat the garbage left by scanf if is to either not use scanf or use a loop.
    while( getchar() != '\n' );

    5. len = strlen( word );
    len is declared as an int, strlen returns size_t. This is nitpicking, but truly portable code will declare len as size_t len;

    6. gets( word );
    Normally I wouldn't even comment on code that uses gets, but I'll make an exception. NEVER use gets, it's been proven to be broken and caused serious problems in the past. gets doesn't check for overflow, you could declare an array of size 20 and enter 500 characters as input and gets will happily write them all to memory that you don't own, possibly crashing your system or worse.

    Note that all of these errors were found in a program that is less than 15 lines. If I wrote code like this I wouldn't have a job for very long. On the positive side the logic seems sound, on the writer's particular system I'm sure these work just fine. Please don't consider this flaming btw, consider it as forceful constructive criticism

    Last edited by Prelude; 02-06-2002 at 12:54 PM.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Why not submit it to the directory on this site?
    I was born; I shall die. Between those two events there is life. I don't know why, and I don't question it; I merely live.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How's my new Website
    By asbo60 in forum General Discussions
    Replies: 53
    Last Post: 07-10-2009, 10:10 AM
  2. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM