im trying to get my head around linked lists and its completely mystifying me my test code wont even compile i get the above error on all the parameters of the second printf and a warning about incompatible pointer type when i try to make the next point to the first element (copied straight out of the book)
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int door_number;
char *p_street_name;
char *p_city;
struct Address *next;
}Address;
int main()
{
Address *first = NULL;
Address *new_address;
Address first_address;
first_address.door_number = 4;
first_address.p_street_name = "some street";
first_address.p_city = "some town";
printf("door number = %d street = %s city = %s\n", first_address.door_number,
first_address.p_street_name, first_address.p_city);
new_address = malloc(sizeof(Address));
if (!new_address)
{
return 1;
}
new_address->door_number = 2;
new_address->p_street_name = "some other street";
new_address->p_city = "some other town";
new_address->next = first;
first = new_address;
printf("door number = %d street = %s city = %s\n", first_address[1].door_number,
first_address[1].p_street_name, first_address[1].p_city);
free(first);
free(new_address);
return 0;
}
coop