#include #include #include #include #include #define INITIAL 10 /* typedef struct character charact_t; struct character { char* characteristics; charact_t* nextcharac; }; */ char* strdup(const char *s1); typedef struct finger finger_t; struct finger { int fnum; char** chracs; finger_t* next; }; typedef struct record record_t; struct record { int id; char* desc; finger_t* fingers; record_t* left; record_t* right; }; typedef struct tree tree_t; struct tree { record_t *root; }; /* #include "treeops.c" #include "listops.c" */ static int queries_handled = 0; /* Number of queries you have completed */ int query_count() { return(queries_handled); } void load_fingerprints(FILE *fingerprints) { } void process_queries(FILE *queries) { } tree_t *make_empty_tree(void) { tree_t *tree; tree = malloc (sizeof (tree_t)); assert (tree!=NULL); tree->root = NULL; return tree; } record_t* recursive_insert (record_t* root, record_t *new) { if(root==NULL) { return new; } else if (new->id id) { root->left=recursive_insert (root->left, new); }else if (new->id id) { root->right=recursive_insert (root->right, new); } return root; } tree_t* insert_in_order (tree_t* tree, record_t* record) { /*insert record into tree*/ tree->root = recursive_insert (tree->root, record); return tree; } finger_t* build_one_finger (FILE* line) { int c,i=0; finger_t* f; int fingernum, num_characteristics=0; char ** characteristics; char temp [100]; /*read in finger num & store it in temp * do that with getc until ':' * */ while ((c=fgetc(line)) != ':') { temp[i]=c; i++; } temp[i] = '\n'; fingernum=atoi(temp); characteristics = malloc (INITIAL *sizeof(*characteristics) ); /* loop in the rest of the line and store each individual string into temp * this loop ends when it reaches end of the line */ i=0; while ((c=fgetc(line)) !='\n') { while (c == ' ') { /*skips past spaces before the first characteristics*/ } while (c !=' ') { temp[i]=c; i++; } temp[i] = '\n'; i=0; characteristics[num_characteristics] = strdup(temp); num_characteristics++; /* end of loop */ } f = malloc(sizeof(*f)); f->fnum = fingernum; f->chracs = characteristics; f->next = NULL; return f; } record_t* build_one_record (finger_t *f, int id, char *desc) { record_t* r; r = malloc(sizeof(*r)); r->fingers = f; r->id = id; r->desc=desc; r->left = NULL; r->right = NULL; return r; } void load_records(FILE *fp) { int id,c; char *desc, *line; char temp2 [100]; int i=0; FILE* tempfilepointer; finger_t *f_head = NULL, *f_tail = NULL; finger_t *newfinger = NULL; tree_t *rtree = NULL; /* rtree=make_empty_tree();*/ record_t *newrecord = NULL; tempfilepointer = fopen("line", "w"); while ((c=fgetc(fp)) !=EOF) { /* record loop, stop at the end of file */ while(c != '\n') { /*read in the id, store*/ if (c == '#') { while (c !=' ') { temp2[i]=c; i++; } temp2[i]='\n'; id= atoi(temp2); i=0; while (c == ' ') { /*skips past the space*/ } /*read in the text, store*/ while (c != '\n') { temp2[i]=c; i++; } temp2[i]='\n'; desc= temp2; i=0; /*get one line*/ }else { while (c!='\n') { temp2[i]=c; i++; } temp2[i]='\n'; line= temp2; } i=0; if (line!="") { fprintf(tempfilepointer, "%s\n", line); newfinger = build_one_finger (tempfilepointer); if (f_head == NULL) { f_head = newfinger; f_tail = newfinger; }else { f_tail->next = newfinger; f_tail = newfinger; } } } /*get another line*/ } /*fingers have all been read in at this point*/ newrecord = build_one_record(f_head, id, desc); /*we have a new record!*/ /*insert record into tree*/ rtree=insert_in_order (rtree,newrecord); /* if (rtree == NULL) { rtree = newrecord; } else */ }