Note that there are some explanatory texts on larger screens.

plurals
  1. POfread not reading struct
    primarykey
    data
    text
    <p>I have the following code that writes structs to a file like so: </p> <pre><code>void write_assignments_to_file(list* assignments, FILE* file) { while (assignments != NULL) { fwrite(assignments-&gt;a, sizeof(assignments-&gt;a), 1, file); assignments = assignments-&gt;next; } fclose(file); } </code></pre> <p>This is writing to the file but when I try to read the file again it hangs my code for reading looks like:</p> <pre><code>list* read_assignments_from_file(FILE* file) { Assignment* assignment; list* item; item = NULL; while ( fread(assignment, sizeof(assignment), 1, file) ) { printf("Reading an assignment in"); insert(item, assignment); } fclose(file); return item; } </code></pre> <p>My insert method looks like: </p> <pre><code>list* insert(list* assignment_pointer, Assignment* new_assignment) { list* ap = assignment_pointer; if(assignment_pointer != NULL){ while (assignment_pointer-&gt;next != NULL) { assignment_pointer = assignment_pointer -&gt; next; } assignment_pointer -&gt; next = (struct list*)malloc(sizeof(list)); assignment_pointer = assignment_pointer -&gt; next; assignment_pointer -&gt; next = NULL; assignment_pointer -&gt; a = new_assignment; return ap; } else { assignment_pointer = (list*) malloc (sizeof(list)); assignment_pointer -&gt; next = NULL; assignment_pointer -&gt; a = new_assignment; return assignment_pointer; } } </code></pre> <p>My struct definition for Assignment looks like:</p> <pre><code>typedef struct Assignment { char* moduleTitle; char* moduleId; char* title; char* author; time_t date_set; time_t date_due; int weighting; } Assignment; </code></pre> <p>So whats causing my program to hang?</p>
    singulars
    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