This is my project for a data structures class using C. I typed out all the functions but i still dont understand why it wont compile can anyone give me any help tips or information thanx. Here is my code.
Code:#include <stdio.h> const short STR_MAX = 41; typedef struct { short year; char picture[STR_MAX]; char director[STR_MAX]; } PICTURE; int main (void) { void instr (void); LIST *buildList (void); void process (LIST *list); /*local declaration*/ LIST *list; /*statement*/ instr (); list = buildList (); process (list); printf("End Best Pictures\n" "Hope you found your favorite!\n"); return 0; }/*main*/ /*=======================instr====================================*/ void instr (void) { /*statements*/ printf("This program will print the academy awards,enter year\n"); return; }/*instr*/ /*=========================buildList==============================*/ LIST *buildList (void) { /*Local Declarations*/ FILE *fpData; LIST *list; short yearIn; char picIn[STR_MAX]; char dirIn[STR_MAX]; PICTURE *pPic; /*Statements*/ list = createList (cmpYear); if (!list); printf("\aCannot create list\n"), exit(100); fpData = fopen("pictures.dat", "r"); if (!fpData) printf("\aError opening input file\n"), exit(100); while (fscanf(fpData," %hd", &yearIn)==1) { if (!(pPic = (PICTURE*)malloc(sizeof(PICTURE)))) printf("\aOut of Memorey in build list\n"), exit(100); pPic->year = yearIn; /* Skip tabs and quote */ while ((fgetc(fpData)) != '\t'); while ((fgetc(fpData)) != '"'); fscanf(fpData, " %40[^\"], %*c", pPic->picture); /*skip tabs and quote */ while ((fgetc(fpData)) != "\t'); while ((fgetc(fpData)) != '"'); fscanf(fpData, " %40[^\"], %*c", pPic->director); /* Insert into list */ addResult = addNode (list,pPic); if (addResult != 0) if (addResult == -1) printf("Memory overflow adding movie\a\n"), exit(120); else printf("Duplicate year %hd not added\n\a", pPic->year); while (fgetc(fpData) != '\n'); } return list; } /*buildList*/ /*=============================cmpYear===========================*/ int cmpYear (void *pYear1, void *pYear2) { /*local definitions*/ int result; short year1; short year2; /*statements*/ year1= ((PICTURE *)pYear1)->year; year2= ((PICTURE *)pYear2)->year; if (year1 < year2) result = -1; else if (year1 > year2) result = +1; else result = 0; return result; }/*cmpYear*/ /*============================process============================*/ void process (LIST *list) { /*statements*/ void printList (LIST *list); void search (LIST *list); char getChoice (void); /*local declarations*/ char choice; /*statements*/ do { choice = getChoice (); switch (choice) { case 'P':printList (list); break; case 'S':search (list); case 'Q':break; }/*switch*/ }while (choice !='Q'); return; }/*process*/ /*==========================getChoice==============================*/ char getChoice (void) { /*localDeclarations*/ char choice; int valid; /*statements*/ printf("================MENU====================\n" "Here are your choices:\n" " S: Search for a year\n" " P: Print all years\n" " Q: Quit \n\n" "Enter your choice: "); do { scanf(" %c", &choice); choice = toupper (choice); switch (choice) { case 'S': case 'P': case 'Q': valid = 1; break; default: valid = 0; printf("\aInvalid choice\n" "Please try again: "); break; }/*switch*/ } while (!valid); return choice; }/*getChoice*/ /*===========================printList===========================*/ void printList (LIST *list) { /*local declarations*/ int location; PICTURE *pPic; /*statements*/ /*getFirstNode*/ if (listCount (list) == 0) printf("Sorry, nothing in list\n\a"); else { printf("\nBest Pictures List\n"); traverse (list,0,&pPic); do { printf("%hd %-40s %s\n", pPic->year, pPic->picture, pPic->director); }while (traverse (list,1,&pPic)); }/*else*/ printf("End of Best Pictures List\n\n"); }/*printList*/ /*==========================search================================*/ void search (LIST *list) { /*local declarations*/ short year; short found; PICTURE pSrchArgu; PICTURE *pPic; /*statements*/ printf("enter a four digit year: "); scanf("%hd", &year); pSrchArgu.year = year; found = searchList (list, &pSrchArgu, &pPic); if (found) printf("%hd %-40s %s\n", pPic->year,pPic->picture, pPic->director); else printf("Sorry, but %d is not available.\n",year); return; }/*search*/



LinkBack URL
About LinkBacks


