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);
exit(1);
}
//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;
}
fclose(fp);
// Display List
printf("\n%s", Ttranstype);
printf("\n%s", Ttranscount);
printf("\n%s", Tunitcost);
return 0;
}
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.