Re: AFL (Australian Football League)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Heathfield

    Re: AFL (Australian Football League)

    Bert said:
    Here's my problem:
    >
    <spec snipped>
    >
    Here's my code so far
    >
    #include <stdio.h>
    >
    struct group* nextseat(struct group g[], int ngroups);
    int main()
    {
    /*************** *************** **********/
    FILE* in = fopen("aflin.tx t" , "r");
    You fail to check whether this call succeeded - fopen returns a null
    pointer if it cannot open the file. You need to decide what you should do
    in that circumstance, and then add code to carry out that plan if the file
    fails to open. For example, you might prompt the user to give you a
    different filename, or you might simply print an error message and quit.
    But you can't just *assume* that the file will be opened successfully, not
    if your goal is to become a good programmer.

    <snip>

    If you're thinking "but he didn't answer my question!", you're probably
    right - I probably didn't. But for all I know, your failure to check that
    the file opened successfully *might* be the solution to your problem.

    I hope that you will become a great programmer some day, and the way in
    which I answer your questions is, believe it or not, designed to help you
    achieve that. I suppose you will be annoyed by my point about fopen, and I
    can't help that. What I'm hoping is that you'll say, "okay, fine, if
    that's the way that pedantic SOB wants to play it, I'll give him a program
    that checks the darn value and takes appropriate action if it's NULL -
    then he won't have that excuse in future". And then we'll move on to the
    next thing you're not doing right... and eventually you'll get this stuff
    right without even thinking about it. And at that point, whether or not
    you continue to do these little programming contest things, you'll be well
    on the way to becoming a Real Programmer(tm).

    --
    Richard Heathfield <http://www.cpax.org.uk >
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
Working...