Thread: Help Please cant figure out why?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Location
    Fiji
    Posts
    212

    Help Please cant figure out why?

    Hi, Im working on an assignment for Uni, could someone please check my code. I am using Linux Redhat 7.1 compiler (gcc/g++ is the required compiler) for uni. My output is:


    2000 14 January Tuesday 8:30 PM 0746347976 1.25
    2000 12 January Sunday 12:01 AM 0754658009 1.98
    2000 15 March Wednesday 1:00 PM 0754621915 12.37
    p 369:1075503696 Pâ?@ @ 0.00

    The first three lines are correct (they are the contents of the file) the last one is the problem it shouldn't print it.

    The ass.cpp file is testing the adt.h. The adt.h file is the main problem i believe in the getrecords function.

    All help and ideas will be appreciated
    Thanks in advance.

    kwigibo
    Last edited by kwigibo; 10-10-2001 at 08:14 PM.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Okay, here's the problem...
    Code:
    int main(){
    
    node *current, *temp;
    
        printf("\n\n");
        //current = create_list();
        get_records(/*current*/);
        do{
            printf("%s %s %s %s %d:%.2d %s %s %.2f\n", current->DETAILS.year, current->DETAILS.date, current->DETAILS.month, current->DETAILS.day, current->DETAILS.hour, current->DETAILS.min, current->DETAILS.TimeOfDay, current->DETAILS.number, current->DETAILS.cost);
            temp = current->next;
            current = temp;
        }while(temp != NULL);
        puts("\n");
    }
    Now, you'll notice here that you declare current, but you don't ever actually initialize it to point at the list. So when you print what current's pointing to, you get meaningless output and a crash.
    The only reason that you're getting anything to print out is because in get_records, you make it print out the nodes while it adds them to the linked list. Once it finishes that, it tries printing them in main, and BOOM.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Location
    Fiji
    Posts
    212
    Thanks heaps, I feel stupid. I overlooked that totally. I was looking at the loop. Jeez thanks heaps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3 dimensional figure volume
    By thekautz in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2009, 05:22 PM
  2. Can't figure out why code is hanging up
    By Panserbjorn in forum C Programming
    Replies: 3
    Last Post: 10-28-2007, 05:09 PM
  3. trying to figure out someone's code for a plugin
    By paulpars in forum C++ Programming
    Replies: 4
    Last Post: 07-20-2006, 10:57 AM
  4. newb to C, cant figure something out.
    By Phate4219 in forum C Programming
    Replies: 16
    Last Post: 03-06-2006, 01:47 AM
  5. I can't figure out this compiler error
    By lime in forum C Programming
    Replies: 7
    Last Post: 07-25-2003, 05:09 PM