Like Tree5Likes

Linked Lists programming help required, output is being blocked by some code :(

This is a discussion on Linked Lists programming help required, output is being blocked by some code :( within the C Programming forums, part of the General Programming Boards category; I scanned that, I dont have time to read it all but im not expecting you to do it for ...

  1. #16
    Registered User
    Join Date
    Apr 2013
    Posts
    10
    I scanned that, I dont have time to read it all but im not expecting you to do it for me, And im not expecting you guys to definately find the answer, it was more a, Well these guys know more about it than me, Maybe they can help, If they cant, i can't complain because its not like i can do it myself,

    And sorry i assumed people would run the code and get the same results, Thats bad on my behalf for expecting you to have the time to compile it, i apologize.

    The results in which i am getting when i run the program are...
    "the list after 4 structs insertion...Current node list:
    PCB_ID: 1111 Arrival Time: 0 CPU_Burst: 0
    PCB_ID: 2222 Arrival Time: 2 CPU_Burst: 1
    PCB_ID: 3333 Arrival Time: 3 CPU_Burst: 2
    PCB_ID: 4444 Arrival Time: 8 CPU_Burst: 3
    PCB_ID: 5555 Arrival Time: 12 CPU_Burst: 7
    PCB_ID: 6666 Arrival Time: 15 CPU_Burst: 10
    PCB_ID: 7777 Arrival Time: 17 CPU_Burst: 4
    <<<<<<<<<<<<<<<< The End >>>>>>>>>>>>>>>>>>

    Removing the last node of the list generates :
    Current node list:
    PCB_ID: 1111 Arrival Time: 0 CPU_Burst: 0
    PCB_ID: 2222 Arrival Time: 2 CPU_Burst: 1
    PCB_ID: 3333 Arrival Time: 3 CPU_Burst: 2
    PCB_ID: 4444 Arrival Time: 8 CPU_Burst: 3
    PCB_ID: 5555 Arrival Time: 12 CPU_Burst: 7
    PCB_ID: 6666 Arrival Time: 15 CPU_Burst: 10
    <<<<<<<<<<<<<<<< The End >>>>>>>>>>>>>>>>>>

    inserting a new head of the list generates :
    Current node list:
    PCB_ID: 6666 Arrival Time: 15 CPU_Burst: 10
    PCB_ID: 1111 Arrival Time: 0 CPU_Burst: 0
    PCB_ID: 2222 Arrival Time: 2 CPU_Bu"

    And it just cuts out, its only started doing this since i added the new insertIn function,
    I'm just not sure why, I've tired using multiple compilers and still the same results

  2. #17
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    Any compiler to the rescue? You need to start using your debugger - This was already shown to you. - Time to complete the job is short, you could probably fix it in good time with the debug effort
    Last edited by rogster001; 04-05-2013 at 03:20 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #18
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    What issue? Your inability to experiment using the debugger? - despite not having any lessons on it? - Or the issue at hand with your code project?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  4. #19
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    OK, here's a short explanation of Salem's debugging session:

    Code:
    Program received signal SIGSEGV, Segmentation fault.
    0x0000000000400b1a in insertIn (CPU_Burst=0x6030d0) at bar.c:297
    297            if(currNode->PCB_Data->CPU_Burst >= newNode->PCB_Data->CPU_Burst)
    (gdb) bt
    #0  0x0000000000400b1a in insertIn (CPU_Burst=0x6030d0) at bar.c:297
    #1  0x0000000000400949 in main () at bar.c:165
    (gdb) list
    292        trailNode = NULL;
    293    
    294            /*traversal list to find insert location */
    295        while(currNode !=NULL)
    296        {
    297            if(currNode->PCB_Data->CPU_Burst >= newNode->PCB_Data->CPU_Burst)
    298            {
    299    
    300              break;
    301
    The program crashes at line 297 in the insertIn() function (the command 'bt' gives a backtrace of all current frames).

    Code:
    (gdb) info locals
    currNode = 0x6030f0
    trailNode = 0x0
    newNode = 0x6031b0
    (gdb) print currNode->PCB_Data
    $1 = (struct PCB *) 0x603010
    (gdb) print *currNode->PCB_Data
    $2 = {PCB_ID = 1111, ArrivalTime = 0, CPU_Burst = 0}
    (gdb) print *newNode->PCB_Data
    Cannot access memory at address 0x0
    In a debugger you can look at the current values of your variables. In your case, "newNode->PCB_Data" is a NULL pointer which you try to dereference at line 297.

    HTH, Andreas

  5. #20
    Registered User
    Join Date
    Apr 2013
    Posts
    10
    Thankyou very much! that is so helpful i will get straight on it! Thankyou for all your help guys, Now i know where the issue is i can begin to solve it!
    You were all a really big help, I learnt alot!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-21-2012, 11:01 PM
  2. Replies: 1
    Last Post: 07-17-2012, 12:56 AM
  3. Double Linked Dynamic Lists Vs Unrolled Linked Lists
    By lantzvillian in forum C Programming
    Replies: 6
    Last Post: 02-14-2012, 12:07 PM
  4. Sorting Linked Lists (code not concept)
    By Newbie Magic in forum C++ Programming
    Replies: 2
    Last Post: 05-11-2004, 08:57 AM

Tags for this Thread


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