Thread: Could have been a homework

  1. #1
    Registered User
    Join Date
    Feb 2002

    Could have been a homework


    This weekend I felt I wanted to get back to my roots. No mfc or windows. no fancy graphics, so I wrote a strict C program handling the inventory on a car spare part store. You know one of those homework tasks with a doubly linked list and pointers twidling. Anyway I realised how fast I forgete things.

    There are some input functions(getchar() fgets().,,,etc) that aren't looked upon as safe. What input functions should I stay away from?.Any other standard functions that are dangerous or bad practice to use. What is your favorit function to hate?

    After a while the file get pretty big, When do you guys split the file? 500 lines, 1000lines, 2000lines,???

  2. #2
    Registered User
    Join Date
    Dec 2001
    Dangerous I/O Functions...

    As a general rule, any string I/O function which doesn't accept a length argument is dangerous. These functions will merilly walk through memory, off the end of your allocated portion, and into the realms of undefined behaviour land.

    gets() is notorious for this, as is scanf using just "%s" without specifying limit lengths IIRC.

    On the other hand, fgets() is perfectly fine - you cannot buffer overrun using it because it will only read characters up to the length passed to it as an argument.

    Just think when using an I/O function "could a buffer overrun occur if I use this function?" and you should quickly decide what is safe and what is not!

    File Organisation

    I organise the 'files' which make up any of my programs as is natural for the program. I would typically have a .h and .c for various ADTs I'm about to use and a collection of files for various subsystems. This part usually follows the programs own internal structure reasonably well. This organisation system doesn't limit file sizes - but usually if I'm over 500 lines I'm either in a large module which should be organised better (aka, more subsystems) or it's raw data (read: arrays containing numerical tables or similar) used by another module.

    Ian Woods

  3. #3
    Join Date
    Feb 2002
    [off topic] Hairyian..... LOL, that's a great name!!!![\off topic]
    Visit - It's what your PC is made for!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum A Brief History of
    Replies: 11
    Last Post: 11-03-2001, 04:39 PM
  2. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 04:49 PM
  3. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 03:16 PM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 01:26 PM