anything wrong with this?

From: atv (atv-nospam_at_xs4all.nl)
Date: 12/13/03


Date: Sat, 13 Dec 2003 21:46:38 +0100

Hi,
is there something wrong with this code? It seems that it crashes
at the else { clause, when allocating a second record. Excuse for
the indentation, the g_warnings are from gtk.

Also, i'm using 2 pointers in the struct, which consists of 3 ints,
and 2 pointers, which i give 256 bytes each. Much to much ofcourse,
but it's just testcode.

The code doesn't even reach the g_warning in the { code.
Any help most appreciated.
atv

if(tail==NULL) {
        g_warning("First record in schedule allocated");
        tail=(schedule *)malloc(256);
        tail->string=malloc(256);
        tail->timestamp=malloc(256);
        strcpy(tail->string,string);
        strcpy(tail->timestamp,asctime(tstruct));
        tail->year=tstruct->tm_year;
        tail->month=tstruct->tm_mon;
        tail->day=tstruct->tm_mday;
        tail->next=NULL;
        head=tail;
        } else {
        g_warning("New record in schedule allocated");
        /* First check if a day is already booked */
        while(tmp!=NULL) {
        g_warning("Checking for double appointment");
        if(!strcmp(tmp->timestamp,asctime(tstruct))) {
        gtk_widget_hide(window1);
        return -1;}
        tmp=tmp->next;
        }
        tail->next=(schedule *)malloc(256);
        tail=tail->next;
        tail->string=malloc(256);
        tail->timestamp=malloc(256);
        strcpy(tail->string,string);
        strcpy(tail->timestamp,asctime(tstruct));
        tail->year=tstruct->tm_year;
        tail->month=tstruct->tm_mon;
        tail->day=tstruct->tm_mday;
        tail->next=NULL;



Relevant Pages

  • Re: Good C programming style
    ... > I'm thinking about a good programming style, pros and cons of some topics. ... this has nothing to do with indentation... ... > - function variables: they're used to java, so no pointers. ...
    (comp.lang.c)
  • Re: Debian Linux on a mac?
    ... so please excuse me jumping in here. ... Any pointers welcome -- I'm in the process of reading the Debian ... Mac install instructions, but pointers always welcome. ...
    (Debian-User)
  • Re: no compile error, but cant run
    ... > I compiled this program without error or warning, ... Not surprising considering that you forgot about proper indentation. ... it wouldn't hurt to have those pointers in the vector actually ...
    (comp.lang.cpp)
  • Re: INTEGER and CHARACTER POINTERS F77?
    ... pointers at all. ... I'll try as an excuse that I had already ranted enough on ... Richard Maine ... domain: summer-triangle ...
    (comp.lang.fortran)
  • Re: Subtracting pointers: Which type to use to store the result?
    ... Assume I have two pointers p1 and p2, which both point to a memory ... assumption, I still think it was the OP's intention, due to the phrasing. ... But that's no excuse. ...
    (comp.lang.c)