|
楼主 |
发表于 2006-11-23 14:21:28| 字数 3,429| - 中国–四川–绵阳 联通/广电网
|
显示全部楼层
公布源代码了...
- #include <windows.h>
- #include <stdio.h>
- #include "resource.h"
- #define STANDARD_ANSWER "!Standard Answer.txt"
- #define NUMQUES 100
- #define LENANS 5
- int WINAPI WinMain(HINSTANCE hInstance,
- HINSTANCE hPreInstance,
- LPSTR strCmdLine,
- int nShowMode)
- {
- char c;
- FILE *pFileAns;
- int iAns=0;
- int index=0;
- int score=0;
- char StdAns[NUMQUES+1][LENANS];
- char ExcAns[NUMQUES+1][LENANS];
- for(int i=1;i<=NUMQUES;i++)
- for(int j=0;j<LENANS;j++)
- {
- ExcAns[i][j]='\0';
- StdAns[i][j]='\0';
- }
- char SamAns[LENANS]="\0";
- char szScoreReport[MAX_PATH*5]="\0";
- char szScoreDetail[MAX_PATH*5]="\0";
- BOOL bIsStdAns=TRUE;
- BOOL bException=FALSE;
- WIN32_FIND_DATA FindFileData;
- HANDLE hFind=FindFirstFile("*.txt",&FindFileData);
- if(lstrcmpi(FindFileData.cFileName,STANDARD_ANSWER))
- {
- MessageBox(NULL,"Cannot find !Standard Answer.txt or one or more file names are improper. Rename these files \nand ensure that !Standard Answer.txt is the first file(arranged by name) in that directory.",
- "Error",MB_OK|MB_ICONERROR);
- return FALSE;
- }
- do
- {
- if(FindFileData.cFileName[0])
- pFileAns=fopen(FindFileData.cFileName,"r");
- do
- {
- c=fgetc(pFileAns);
- }
- while(!(c>='0' && c<='9') && !feof(pFileAns));
- while(!feof(pFileAns))
- {
- if(c>='0' && c<='9')
- {
- if(index && !bIsStdAns)
- {
- if(!lstrcmpi(SamAns,StdAns[index]))
- score++;
- else if(!lstrcmpi(SamAns,ExcAns[index]) && SamAns[0]!='\0')
- score++;
- else
- {
- char szBuffer[MAX_PATH];
- (ExcAns[index][0]=='\0')? wsprintf(szBuffer,"%d\t%s\t%s\n",index,SamAns,StdAns[index]):
- wsprintf(szBuffer,"%d\t%s\t%s/%s\n",index,SamAns,StdAns[index],ExcAns[index]);
- lstrcat(szScoreDetail,szBuffer);
- }
- for(int i=0;i<iAns;i++) SamAns[i]='\0';
- }
- iAns=0;
- bException=FALSE;
- char c1=fgetc(pFileAns);
- if(c1>='0' && c1<='9')
- {
- char c2=fgetc(pFileAns);
- if(c2>='0' && c2<='9')
- {
- index=(c-'0')*100+(c1-'0')*10+c2-'0';
- do
- {
- c=fgetc(pFileAns);
- }
- while(c>='0' && c<='9' && !feof(pFileAns));
- }
- else
- {
- index=(c-'0')*10+c1-'0';
- c=c2;
- }
- }
- else
- {
- index=c-'0';
- c=c1;
- }
- }
- if(c>='A' && c<='Z' || c>='a' && c<='z')
- {
- if(bIsStdAns)
- {
- if(bException)
- ExcAns[index][iAns++]=c;
- else
- StdAns[index][iAns++]=c;
- }
- else
- SamAns[iAns++]=c;
- }
- if(c=='/' && bIsStdAns)
- {
- iAns=0;
- bException=TRUE;
- }
- c=fgetc(pFileAns);
- }
- // For the last entry
- if(!bIsStdAns)
- {
- if(!lstrcmpi(SamAns,StdAns[index]))
- score++;
- else
- {
- char szBuffer[MAX_PATH];
- wsprintf(szBuffer,"%d\t%s\t%s\n",index,SamAns,StdAns[index]);
- lstrcat(szScoreDetail,szBuffer);
- }
- for(int i=0;i<iAns;i++) SamAns[i]='\0';
- iAns=0;
- // Write Report
- wsprintf(szScoreReport,
- "Score Report for %s \n\nScore: %d\n\nQuestions answered incorrectly:\n\nNum \tAns \tStd \n===================\n%s",
- FindFileData.cFileName,score,szScoreDetail);
- char RepName[MAX_PATH]="ScoreReport_";
- //Change .txt to .log
- char *pch=strrchr(FindFileData.cFileName,'.');
- FindFileData.cFileName[pch-FindFileData.cFileName]='\0';
- lstrcat(FindFileData.cFileName,".log");
- FILE *pFileRep=fopen(lstrcat(RepName,FindFileData.cFileName),"w");
- fprintf(pFileRep,"%s",szScoreReport);
- fclose(pFileRep);
-
- wsprintf(szScoreReport,
- "Score of %s: %d\n\n See ScoreReport_%s for details.",
- FindFileData.cFileName,score,FindFileData.cFileName);
- MessageBox(NULL,szScoreReport,"Score Report",MB_OK);
- }
- // Clean-up for the next sample file
- index=0;
- score=0;
- szScoreDetail[0]='\0';
- szScoreReport[0]='\0';
- bIsStdAns=FALSE;
- fclose(pFileAns);
- }while (FindNextFile(hFind, &FindFileData) != 0);
- FindClose(hFind);
- return 0;
- }
复制代码 |
|