Note that there are some explanatory texts on larger screens.

plurals
  1. POC, creating one way linked list from file
    primarykey
    data
    text
    <p>Got it working. I'm just dumb and wrote <code>=</code> instead <code>==</code> in one place t.t Thanks all.</p> <p>I have file with my data, and now i want to read it and put it into list. I don't fully know how to do it and since I have to finish this project in near future I simply ask you for help ;]</p> <p>header file:</p> <pre><code>typedef struct { char category[50]; char name[50]; char ingredients[50]; char instruction[1000]; }recipe_t; typedef struct element { struct element *next; recipe_t recipe; } el_list; void all_recipe_list(); void show_all_list(el_list *list); void add_new_element_to_list(el_list *list, recipe_t formula); </code></pre> <p>my list functions file:</p> <pre><code>void all_recipe_list() //reading all record into list + show it(show_all_list function) { FILE *database; recipe_t formula; el_list *head; head = NULL; database = fopen(filename, "rb"); fgetc(database); // function feof returns value only if we read something before, so in order to check if its end, we try to read one char // when writing data to file, I put \n always before new record while (!feof(database)) { fread(&amp;formula, sizeof(recipe_t),1,database); if (head == NULL) { head = malloc(sizeof(el_list)); head-&gt;recipe = formula; head-&gt;next = NULL; } else { add_new_element_to_list(head,formula); } fgetc(database); // same as above } fclose(database); show_all_list(head); } void show_all_list(el_list *list) { el_list *p=list; while (p != NULL) { printf("Kategoria:%s\n", p-&gt;recipe.category); printf("Nazwa:%s\n", p-&gt;recipe.name); printf("Skaldniki:%s\n", p-&gt;recipe.ingredients); printf("Instrukcja:%s\n", p-&gt;recipe.instruction); p = p-&gt;next; } } void add_new_element_to_list(el_list *list, recipe_t formula) { el_list *p, *new_el; p = list; while (p-&gt;next != NULL) { p = p-&gt;next; } new_el = malloc(sizeof(el_list)); new_el-&gt;recipe = formula; new_el-&gt;next = NULL; p-&gt;next= new_el; } </code></pre> <p>What are the problems? Program is compiling allright but it's crashing when all_recipe_list is called. It's probably something wrong with add_new_element_to_list. Can't figure out what though. Also I don't know if in show_all_list p->recipe.category is right way to do it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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