Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting an error with regards to char arrays inside of a linked list?
    text
    copied!<p>Just trying to wrap my head around linked lists. I'm getting an error "incompatile types when assigning to type char[50]" also "string constant is too long" And finally invalid type argument '->' in the last struct. What do I need to fix? </p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;ctype.h&gt; #include &lt;string.h&gt; struct trainset { char name[50]; int price; struct trainset *next; }; void show_list(struct trainset *list); int main (void){ struct trainset *root; root = (struct trainset *)malloc(sizeof(struct trainset)); strncpy(root -&gt;name, " ", 50); root -&gt;price = 0; root -&gt;next = 0; struct trainset *first_train; first_train = (struct trainset *) malloc(sizeof(struct trainset)); root -&gt;next = first_train; strncpy(first_train-&gt;name, "Fantasy Train Set", 50); first_train-&gt;price = 129; first_train-&gt;next = NULL; struct trainset *second_train; second_train = (struct trainset *)malloc(sizeof(struct trainset)); first_train-&gt;next = second_train; strncpy(first_train-&gt;name, "Uncle Bobs train set", 50); second_train -&gt;price = 69; second_train -&gt;next = NULL; struct trainset *third_train; third_train = (struct trainset *)malloc(sizeof(struct trainset)); second_train-&gt;next = third_train; strncpy(third_train -&gt;name, "Budha Bread Train", 50); third_train -&gt;price = 169; third_train -&gt;next = NULL; show_list(first_train); return 0; } void show_list(struct trainset *list) { while(list-&gt;next!=NULL) { printf("train set name: %s, Train price: %d\n", list-&gt;name, list-&gt;price); list = list-&gt;next; } printf("train set name: %s, train price: %d", list-&gt;name, list-&gt;price); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload