Computer Science 2574 |
Intro to Data Structures & Soft Eng
|
/*----------------------------------------------------------------- -Module Name: odbread.c -Interface File: odbread.h -Implementation File: odbread.c -Description: - This module is responsible for reading in the file information - from the raw OPSCAN file, reading the class header info from - the user, and inserting the student information into a linked - list. - -Functions: Name Purpose - ReadFile Read opscan file - ReadHeader reads opscan file header info - ReadRecord reads a record from the opscan file - InsertRecord inserts the new record at the end of the list - CloseFile closes the file after reading it - -Called by: main -Calls: -Author: Jon Ford -Revision: 3/27/96 -Version: 1.1 -------------------------------------------------------------------*/ #include#include #include #include"odbread.h" #include "geosim.h" #define ONEQMARK "?" #define QMARKS "?????????" /*these functions are not called from any external modules*/ /*and therefore are not prototyped in the header file*/ void ReadHeader(ListMgr listmgr); void ReadRecord(ElemPtr tempelem, ListMgr listmgr); /*---------------------------------------------------------------- -Funciton Name: ReadFile -Description: - This function is the coordinating function for getting a file - name from the user, reading the data, and inserting it into the - linked list. - -Called by: main -Calls: ReadHeader, ReadRecord,InsertRecord -Parameters: FILE*, ListMgr - -Author: Jon Ford - -Revision: 3/8/96 -Version: 1.1 ------------------------------------------------------------------*/ void ReadFile(ListMgr listmgr) { ElemPtr tempelem; if ((listmgr->title.opfileptr= fopen(listmgr->title.opfilename,"r"))==NULL) { strcpy(listmgr->title.opfilename,"None"); return; } else { ReadHeader(listmgr); listmgr->title.students=0; listmgr->title.total=0; tempelem=CreateElement(); ReadRecord(tempelem,listmgr); while (!feof(listmgr->title.opfileptr)) { listmgr->title.total=(listmgr->title.total+ tempelem->item.score); InsertElement(listmgr,tempelem); listmgr->title.students++; /*count the number of students*/ tempelem=CreateElement(); ReadRecord(tempelem, listmgr); } fclose(listmgr->title.opfileptr); } } /*------------------------------------------------------------ -Funciton Name: ReadRecord -Description: - this function reads each individuall record into memory -pointed to by the structure pointer passed to it. - - -Called by: ReadFile -Calls: none -Parameters: listmgr - pointer to the datastructure - tempelem - where to store the read information - -Author: Jon Ford -Revision: -Version: 1.0 --------------------------------------------------------------*/ void ReadRecord(ElemPtr tempelem, ListMgr listmgr) { char junk[50]; /* these are for strings to be converted*/ char correctcount[50]; char omittedcount[50]; char score[50]; char tscore[50]; fgets (junk, 40, listmgr->title.opfileptr); /*reads to end of line*/ fgets (tempelem->item.SSN,12,listmgr->title.opfileptr); fgets (tempelem->item.lastname, 18, listmgr->title.opfileptr); fgets (tempelem->item.initial1, 3, listmgr->title.opfileptr); fgets (tempelem->item.initial2, 5, listmgr->title.opfileptr); fgets (correctcount,7,listmgr->title.opfileptr); fgets (omittedcount,6,listmgr->title.opfileptr); fgets (tempelem->item.seatnumber, 4,listmgr->title.opfileptr); fgets (tempelem->item.form,4,listmgr->title.opfileptr); fgets (tempelem->item.group,3,listmgr->title.opfileptr); fgets (score,5,listmgr->title.opfileptr); fgets (tscore,3,listmgr->title.opfileptr); tempelem->item.correctcount=atoi(correctcount); tempelem->item.omittedcount=atoi(omittedcount); tempelem->item.score=atof(score); tempelem->item.tscore=atof(tscore); if (tempelem->item.lastname[0]==' ') { strcpy(tempelem->item.lastname,QMARKS); strcpy(tempelem->item.initial1,ONEQMARK); strcpy(tempelem->item.initial2,ONEQMARK); } } /*------------------------------------------------------------ -Funciton Name: ReadHeader -Description: -this function reads the headerinformation based -on whether the file is an opscan file or an odb file - -Called by: ReadFile -Calls: none -Parameters: - listmgr - pointer to the data structure - -Author: Jon Ford -Revision: 3/8/96 -Version: 1.1 ---------------------------------------------------------------*/ void ReadHeader(ListMgr listmgr) { char junk1[80]; /*for discarded file information */ char students[80]; /*for string to be converted to float*/ char questions[80]; if(listmgr->title.filetype==0) { fscanf(listmgr->title.opfileptr, "%s%s%s%s%s%s",listmgr->title.instructor, listmgr->title.department,listmgr->title.course, listmgr->title.title1,listmgr->title.title2, listmgr->title.date); fscanf(listmgr->title.opfileptr,"%s%s%s%d ", junk1,junk1,junk1,&(listmgr->title.students)); fscanf(listmgr->title.opfileptr,"%s",junk1); fscanf(listmgr->title.opfileptr,"%s",junk1); sprintf(listmgr->title.desc,"%17s%4s%5s%10s%5s%10s", listmgr->title.instructor, listmgr->title.department, listmgr->title.course,listmgr->title.title1, listmgr->title.title2,listmgr->title.date); listmgr->title.questions=0; /*default value*/ listmgr->title.newstud=0; /*for adding new students*/ } else { fgets(listmgr->title.desc,80,listmgr->title.opfileptr); fgets(junk1,5,listmgr->title.opfileptr); fgets(junk1,6,listmgr->title.opfileptr); fgets(listmgr->title.date,10,listmgr->title.opfileptr); fgets(junk1,9,listmgr->title.opfileptr); fgets(junk1,9,listmgr->title.opfileptr); fgets(students,5,listmgr->title.opfileptr); fgets(junk1,13,listmgr->title.opfileptr); fgets(questions,5,listmgr->title.opfileptr); listmgr->title.students=atoi(students); listmgr->title.questions=atoi(questions); listmgr->title.desc[50]='\0'; } }