Forum: ARM programming with GCC/GNU tools Reading Data file into Linked List

von Philip A. (Company: Personal) (appiah212)

Rate this post
0 useful
not useful
Please i am new to c,i intend to load content of a file into a linked 
list and display the list, please help debug the code, thank you.

 /* a linked list. */

 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>

 /* The list data structure. */
 struct data {
 char transtype[20];
 char transcount[3];
 char unitcost[3];

 struct data *next;


 /* Define typedefs for the structure */
 /* and a pointer to it. */
 typedef struct data PERSON;
 typedef PERSON *LINK;

 int i;
 char namevar[20];
 FILE *fp;

 int main( void )
 /* Head, new, and current element pointers. */
 LINK head = NULL;
 LINK new = NULL;
 LINK current = NULL;

 if ( (fp = fopen("filename", "rb")) == NULL)
     //fprintf(stderr, “Error opening file %s.”, filename);

 //current = head;
  while (!feof(fp))

       fread(transtype, sizeof(char), 20, fp);
       fread(transcount, sizeof(char),3, fp);
       fread(unitcost, sizeof(char), 3 , fp);

     //  current = current->next;

// Display List
       printf("\n%s", Ttranstype);
       printf("\n%s", Ttranscount);
                   printf("\n%s", Tunitcost);

 return 0;


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.