Thread: Requesting feedback on my code

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    144

    Requesting feedback on my code

    Hello, everyone. I am a self-taught C programmer. I have written part of a word-wrapping program, about 300 lines so far in multiple files. I am requesting feedback about my coding style. I would appreciate honest criticism. Thanks in advance.

    You can download a zip here:
    Dropbox - wrap.zip

    Or use github:
    GitHub - richardcavell/wrap: Word-wrapping program written in C89

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    Everybody is "self-taught".

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,428
    The actual presentation of the code is very good.

    Some comments on details.
    1. Most of the option parsing code should be moved to options.c
    2. options_t is the kind of size where you should be passing around pointers, rather than always passing by value.
    3. Consider using getopt to do the grunt work.
    4. You re-declare open_file(const char *fn, struct options_t options); inside main.
    5. Your default options invocation should be DEFAULT_INVOCATION and not NULL.
    6. In options_t, the member 'int files' is far too non-descriptive.
    7. You have a buffer size in options_t, but no buffer pointer (though you do allocate a buffer in open_file()
    8. if ( buffer ) guarding free(buffer) is a waste, since free(NULL) is a safe operation to begin with.
    9. Operand reversal is so 1980's - EOF == fclose(fp). See Question 17.4
    10. Failing to open/close a file should not normally cause a program to exit.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Posting code for feedback/evaluation.
    By edbarx in forum C Programming
    Replies: 2
    Last Post: 07-15-2016, 01:56 AM
  2. Feedback on prime number generator source code?
    By sepp in forum C Programming
    Replies: 5
    Last Post: 12-21-2014, 09:20 PM
  3. mini game - please feedback on code design
    By CoffeCat in forum C++ Programming
    Replies: 17
    Last Post: 06-13-2012, 02:42 AM
  4. Replies: 3
    Last Post: 10-06-2011, 05:43 PM
  5. Need feedback on code
    By dynamethod in forum C++ Programming
    Replies: 2
    Last Post: 11-24-2007, 03:20 AM

Tags for this Thread