I am having trouble with this program I get the error dereferencing pointer to incomplete type in the populate function I am using BloodShed's Dev C++ compiler v4.9.9.2 I copied this program out of a book because I was having a problem with a linked list in a similar program. I think there is a problem with the compiler not supporting these types of pointer's in a function. I hope someone can help me by telling me what I can set up the complier or if there is an error I don't see, or a way that will make this work.
int main()
{
int i;
struct tel_typ *list, *current; /* Two pointer of type tel_typ*/
char *malloc( ); /* malloc returns a pointer to char /*warning conflicting types for built-in function 'malloc'
/* This will point to each node as it traverses the list */
void populate(struct tel_typ *); /* function prototype*/
void display(struct tel_typ *); /* function prototype*/
/* get a pointer to the first structure and create two more structures */
list = (struct tel_typ *)malloc(sizeof(struct tel_typ));
current = list;
for(i=0; i<2; ++i)
{
populate(current);
current -> nextaddr = (struct tel_typ *)malloc(sizeof(struct tel_typ));
current = current -> nextaddr;
}
populate(current);
current -> nextaddr = NULL;
printf("\nThe list consists of the following records:\n");
display(list);
while (list!=NULL)
{
printf("\n%-30s %-20%s", list -> name, list -> phone_no);
list = list->nextaddr;
}
return;
}
/* get a name and phone number */
void populate(struct tel_type *record)
{
printf("Enter a name: ");
gets(record -> name); /* error dereferencing pointer to incomplete type */
printf("Enter the phone number: ");
gets(record->phone_no); /* error dereferencing pointer to incomplete type */
return;
}
1) Please use code tags when posting code to make it more readable. The easier it is to read your code, the more people will want to help you.
2) What is this supposed to be:
char *malloc( );
It looks like you're declaring a function called malloc that takes no arguments and returns a char *. I'm guessing that's not what you intended. Is this supposed to be a call to the standard library malloc function?