Issues with your account? Bug us in the Discord!

(C) Access Violation >:(

So you see, Im about to kill my computer, run out of the house naked and find a nice big tree to go back to living in.....

Im doing an assignment for Uni that is to implement Bucket Sort right. Well everything was going along nicely till suddenly (strangely enough when I tried to run the full implementation for the first time) the comp tells me that I have stuffed up.

The Idea is that we use list that we have defined in an earlier lab right. Well I want an array of these list to be my buckets for the sort so I did this:

/* create temp array of buckets. */
list *temp;
temp = emalloc(n * sizeof temp[0]);
for(i = 0; i < n; i++) {
temp[i] = list_init();
}

emalloc is just a error version of malloc, n is the number of items I want in the array and list_init()just initiates a new list. This seems to work in my head, but when I do the following it yells blue murder at me:

for(j = 0; j < n; j++) {
k = (int)floor(l->items[j]);
list_append(temp[k],l->items[j]);

Now k is just finding into which bucket the item should go, and list_append just adds it to the end of the list, adding extra space if needed.

Now the problem that occurs is that when the above code calls list_append, it is calling an invalid region of memory(at least thats what I think is happening). I get an access violation because there is no list there to be filled.

Why am I writing this here??? Well, the first reason is that I need to put it out so that I can see what is wrong (writing stuff down helps my head work itself round the abstractions), and secondly cos there are some fine minded ppl that might just be able to help me get over the problem.

So, if'n you can sees a problem, and know how to fix, then please do tell.... I only have a couple of days to finish this... [img]http://216.15.145.59/mainforums/smile.gif[/img]

Comments

  • ok so dont worry bout it, cos I found the problem.... now I just have to find out the right formula to put the numbers into the right buckets... [img]http://216.15.145.59/mainforums/smile.gif[/img]

    Thanks for reading anyway [img]http://216.15.145.59/mainforums/smile.gif[/img]

    ------------------
    D&D: You know your a geek when you convert your entire flat from nice ordinary people to D&D lovin' nerds
    www.oranhide.cjb.net Go there, go now.
  • JackNJackN <font color=#99FF99>Lightwave Alien</font>
    Now I'm about to kill my computer, run out of the house naked and find a nice big tree to go back to living in...
  • Oh Jack.... I know how you feel.. [img]http://216.15.145.59/mainforums/smile.gif[/img]

    Why you want to???

    ------------------
    D&D: You know your a geek when you convert your entire flat from nice ordinary people to D&D lovin' nerds
    www.oranhide.cjb.net Go there, go now.
  • BigglesBiggles <font color=#AAFFAA>The Man Without a Face</font>
    Ah, fun with dynamic memory! I remember when we first learned C's dynamic memory management. I ended up teaching it to a reasonable portion of the class. [img]http://216.15.145.59/mainforums/smile.gif[/img]

    ------------------
    [url="http://www.minbari.co.uk/log12.2263/"]Never eat anything bigger than your own head.[/url]
    "Nonono...Is not [i]Great[/i] Machine. Is...[i]Not[/i]-so-Great Machine. It make good snow cone though." - Zathras
  • PJHPJH The Lovely Thing
    *Dynamic memory allocation unit initializing and preparing to go warp speed..... tinkle dingle dongle* [img]http://216.15.145.59/mainforums/tongue.gif[/img]

    - PJH
  • BigglesBiggles <font color=#AAFFAA>The Man Without a Face</font>
    [img]http://216.15.145.59/mainforums/biggrin.gif[/img]

    ------------------
    [url="http://www.minbari.co.uk/log12.2263/"]Never eat anything bigger than your own head.[/url]
    "Nonono...Is not [i]Great[/i] Machine. Is...[i]Not[/i]-so-Great Machine. It make good snow cone though." - Zathras
  • Always with the *tinkling*

    [img]http://216.15.145.59/mainforums/biggrin.gif[/img] [img]http://216.15.145.59/mainforums/biggrin.gif[/img] [img]http://216.15.145.59/mainforums/biggrin.gif[/img]

    ------------------
    D&D: You know your a geek when you convert your entire flat from nice ordinary people to D&D lovin' nerds
    www.oranhide.cjb.net Go there, go now.
Sign In or Register to comment.