-1

I have this part of structure and a list , and I want to fill up with same values.

  typedef struct node{
    char* place;
    int id;
    int type;
    int price;
    struct node * next;
}node;

typedef struct Hotels{
    char* name;
    char* place;
    char* inf_hotel;
    days*  registration;
    rooms* informations;
    node* head;
}Hotels;

here is my attempt for to fill up the list

int capacity_rooms=25;
int a[25],b[25],c[25];
char str[25][1024];

 struct node *head=malloc(25*sizeof(struct node));
    for ( i=0; i<capacity_rooms; i++ ){
        head[i].id = a[i];
        head[i].price = b[i];
        head[i].type = c[i];
        head[i].place = str[i];
        head[i].next=NULL;
    }

is that correct how i create this linked list , i want to store just this 25 values Correct me if iam wrong.

fjordi
  • 1
  • 5
  • 3
    That's not a linked list, it is just an array of nodes. A linked list is where the `next` pointer of each node holds the address of the next node in the list. Please do basic research. There are countless existing books/tutorials/websites that explain what a linked list is, how to implement the common operations and even full code examples. – kaylum May 21 '22 at 07:44
  • 2
    In `head[i].place = str[i];` the `str[][]` array is local, and so the object of the pointer stored will not persist. – Weather Vane May 21 '22 at 07:47
  • Not the main error, so not closing as a duplicate, but [see this](https://stackoverflow.com/questions/72330113). – n. 1.8e9-where's-my-share m. May 21 '22 at 14:09

0 Answers0