المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : linked list adding operation with two structure type



C++ Programming
05-01-2011, 07:00 AM
hi there i am working on a project that reads some data from a file and storing it into nodes. i actually made some operations like adding,deleting,search ect. in singly linked list with one structure type. now i am trying to use two structure types which are;

typedef struct node { int birth_date; int zipcode; int phone_num; char first_name[50]; char last_name[50]; char city[50]; char address[50]; char email_addr[50]; struct node* fn_next; struct node* ln_next; struct node* birdat_next; } NODE; typedef struct { int count; NODE* head; NODE* tail; NODE* current; }LIST;
and this is the block which i read and store the data and finally call add_Node function;
while ( !feof(myfile) ) { if( !(student = (NODE*) malloc(sizeof(NODE))) ) { printf("ERROR NOT ENOUGH MEMORY!!!\n"); exit(100); } fscanf(myfile,"%s", &(student->first_name) ); fscanf(myfile,"%s", &(student->last_name) ); fscanf(myfile,"%s", &(student->email_addr) ); fscanf(myfile,"%d", &(student->phone_num) ); fscanf(myfile,"%s", &(student->address) ); fscanf(myfile,"%s", &(student->city) ); fscanf(myfile,"%d", &(student->zipcode) ); add_Node(&list,student); printf("%s\n", student->first_name ); } }
and of course add_Node function;

void add_Node(LIST** list, NODE* student) { if( (*list)->head == NULL ) { student->fn_next = (*list)->head; (*list)->head = student; (*list)->tail = student; printf("Adding operation is succesfull\n"); (*list)->count++; return; } else { (*list)->current = (*list)->head; while ( (*list)->current != NULL ) (*list)->current = (*list)->current->fn_next; (*list)->current->fn_next = student; student->fn_next = NULL; (*list)->tail = (*list)->current; return; }}
i am taking segmentation faults in add_Node and i don't know how to fix it.