Lists in C language. Access violation -


this bit tricky explain i'll try anyway. i'm trying create program list ends 0, , has 0s in middle.the program check minimum value between each 0 (for example: list 6 -> 3 -> 15 -> 0 -> 1 ->2 ->0, minimum values 3 , 1) , delete them list, , insert them list.

for example, if list1 6 -> 3 -> 15 -> 0 -> 1 ->2 ->0, after run program, list1 6 -> 15 -> 0 -> 2 ->0 , list2 3->1.

when run code, error of access violation. here's code:

list* essay(list* anchor1) {     list* prev_to_min,*runner,*prev_to_runner,*result,*result_temp;     int min;     prev_to_min=prev_to_runner=anchor1;     result=allocate_list();     result_temp=result;     runner=prev_to_runner->address_to_next;     min=runner->number;     while(runner!=null)     {         while(runner->number!=0)         {             if(min>=runner->number)             {                 min=runner->number;                 prev_to_min=prev_to_runner;             }             prev_to_runner=runner;             runner=runner->address_to_next;         }         remove_item(prev_to_min);         result_temp=insert_item(result_temp,min);         prev_to_runner=runner;         runner=runner->address_to_next;         if(runner!=null)             min=runner->number;     }     return result; } 

a small explanation since there many variables around: result pointer anchor of list2 (the list of minimums), result_temp pointer current last item of list2, runner pointer im using iterate on list1, prev_to_runner points item before runner in list, , prev_to_min points item before minimum in list1. example 6 -> 3 -> 15 -> 0, 3 minimum, prev_to_min address of 6.

i tried run piece of paper, run program in head, , needed result. when compile , computer runs it, error "unhandled exception @ 0x5557700c (msvcr100d.dll) in more lists.exe: 0xc0000005: access violation reading location 0xfffffffc."

this code inserting , item , deleting item:

void remove_item(list* prev_position) {     list* deleted;     deleted=prev_position->address_to_next;     prev_position->address_to_next=deleted->address_to_next;     free(*deleted); }  list* insert_item(list* position,listdata x) {     list* temp=(list*)malloc(sizeof(list));     temp->number=x;     temp->address_to_next=position->address_to_next;     position->address_to_next=temp;     return temp; } 

access violation reading location 0xfffffffc. that's pretty clue had null pointer backuped size of 32 bit integer , tried read it.

if run in debugger, tell where.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -