//Jing Chen //attrib.c #include #include #include #include #include #define SIZE 50 #define filename "../greport.txt" #define RecLine 200 float ext_grade(const char *line, const char *t) /* print the selected grade in this record line */ { int j=0; float tempf; char temp[10],*pos; if ( (pos=strstr(line,t))!=NULL) { while ((*pos)!='=') pos++; pos++; j=0; while ( ((*pos)!=',')&&((*pos)!=')')&& ((*pos)!=';') ) { temp[j]=(*pos); j++;pos++; } temp[j]=0; tempf=(float)(atof(temp)); return tempf; } else { return 0; } } /* extract a string from s between the nth and (n+1)th coma in a line in greport.txt*/ void extract(char s[], char d[],int n) { int len,coma=0,j=0,i; len=strlen(s); for (i=0;i\n") ; printf("Assignments Selected\n") ; printf("\n") ; printf("
"); printf(""); printf(""); printf("",item_width); fgets(line,sizeof(line),f); fgets(line,sizeof(line),f); i=0; while (!finish) { j=0; while ((line[i]!=',' )&& (line[i]!=';')&& (!finish) ) { if ( line[i]==')' ) finish=1; else if (line[i]!=' ') { item[j]=line[i]; j++;i++; } else { i++; } } item[j]=0; if ( (temp=strstr(item,"="))!=NULL ) { (*temp)=0; if ( (temp1=strstr(data, item))!=NULL ) { printf("",item_width,item); target[k]=malloc(strlen(item)+1); strcpy(target[k],item); k++; } } i++; } printf(""); do { printf(""); extract(line,fname,2); extract(line,lname,3); if ((cnt % 2)==0) { printf("", item_width,fname,lname); for (m=0;m%3.1f",item_width,ext_grade(line,target[m]) ); } } else { printf("",item_width,fname,lname); for (m=0;m%3.1f",item_width,ext_grade(line,target[m]) ); } } cnt++; printf(""); fgets(line,sizeof(line),f); }while (! feof(f) ); printf("
Student Name%s
%s %s%s %s
\n"); printf("
\n"); printf("\n"); printf("\n"); fclose(f); }