Issues with your account? Bug us in the Discord!
(C) Access Violation >:(
Schmacker
Ranger
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]
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
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.
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.
------------------
[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
- PJH
------------------
[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
[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.