Mlutiple Linked list Array

C

chellappa

hi Everybody!
i am trying multiple array linked list .. i am trying , but its give
derefernceing pointer to incompelete type .. please help me to correct
this pgm

#include<stdlib.h>
#include<stdio.h>
void insert(int listno,int value);
struct listl {
int val;
struct list * next;
};

typedef struct list item;
item * curr[10], * head[10];

int main(void) {
int i;

for(i=0;i<=9;i++)
{
head = NULL;
}

insert(2,21);
insert(2,2);
insert(2,5);
insert(7,54);
insert(7,45);
insert(7,75);
curr[2] = head[2];
curr[7] = head[7];
while(curr[2]&&curr[7])
{
printf("%d\n%d\n", curr[2]->val,curr[7]->val);
curr[2] = curr[2]->next ;
curr[7] = curr[7]->next ;

}
}
void insert (int listno,int value)
{
curr[listno] = (item *)malloc(sizeof(item));
curr[listno]->val = value;
curr[listno]->next = head[listno];
head[listno] = curr[listno];
}

Thnank u
by
CNS
 
A

Alipha

chellappa said:
...
#include<stdlib.h>
#include<stdio.h>
...
curr[listno] = (item *)malloc(sizeof(item));

don't cast the return of malloc. void* converts to other pointer types
implicitly just fine. A cast could hide the error of you forgetting to
include stdlib.h, if you did forget that. don't cast unnecessarily.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top