Could have been a homework

This is a discussion on Could have been a homework within the C Programming forums, part of the General Programming Boards category; Hi This weekend I felt I wanted to get back to my roots. No mfc or windows. no fancy graphics, ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    591

    Could have been a homework

    Hi

    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,???
    Thanks

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    44
    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
    www.entropysink.com
    Join Date
    Feb 2002
    Posts
    605
    [off topic] Hairyian..... LOL, that's a great name!!!![\off topic]
    Visit entropysink.com - 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 Cprogramming.com
    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, 05:49 PM
  3. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 04:16 PM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 02:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21