{
register int i,m=0;
int len;
FILE*fp,*fpl,*fopen();
char filename1[100],filename2[100],title[100];/*設(shè)定資料變量*/
char subject[10][10];
char id[100][10],password[100][10];
int score[100][20],sum[100],allsum;
float avg[100],alltotalavg;
int rank,number,index,find,j,kind;
printf("content-type:text/html%c%c",10,10);
len=atoi(getenv("CONTENT_LENGITH"));
for(i=0;len && (!feof(stdin));i++){
m=i
inputs[i].val=readdstdin(stdin,&,len);/*讀STDiN信息*/
AddToSpace(inputs[i].val);
Convert(inputs[i].val);
inputs[i].name=ReadData(inputs[i].val,=);
}
strcpy(filename1,"/score/setup/");
stucpy(filename2,"/xcore/data/");
if(strcmp(inputs[o].val,"計算機系/)==0
strcat(filename1,"compusb.dat");
strcat(filename2,"compscore.dat");
}
if(strcmp(inputs[o].val,"英語系")==0
strcat(filenamel,"engsub.dat");
strcat(filename2,"engscore.dat");
}
if(strcmp(inputs[o].val,"無線電系")==0
}
strcat(filename1,"elecsub.dat");
strcat(filename2,"elecscore.dat");
}
fp=fopen(filename1,"r");/*打開文件*/
kind=0;
while(fscanf(fp,"%s",subject[kind]!=EOF
kind=kind+1;
fclose(fp);
fp1=fopen(filename2,"r");/*打開文件*/
allsum=0;
for(i=0;i<100;i++)
{
numbde=i;
if(fscanf(fp1,"%s%s",id[i],
password[i]!=EOF){
sum[i]=0;
for{j=0;j
fscanf(fp1,"%d",&score[i][j]);
sum[i]+=score[i][j];
}
avg[i]=sum[i]/kind;
allsum+=sum[i];
}
else
break;
}
fclose(fp1);
find=0;
if(strcmp(inputs[2].val,id[i])==0&&
strcmp(inputs[3].val,password[i]==0){
index=i;
find=i;
}
}
if(find==0)
{
printf{"
}
else
{
rank=1
for(i=o;i
if(sum[index]
rank=rank+1;
slltotalavg=allsum/number;
printf("
學(xué)生成績查詢系統(tǒng)
pritf("\n
",
inputs[2].val);
printf("\n
");
for(i=0;i
printf{"%s\t",subject[kind]);
printf("總分
\n");
for(i=0;i
printf("%d\t",score[index][i]);
printf["%d
\n",sum[index]);
}
}
五、結(jié)束語
本文以學(xué)竽成績查詢系統(tǒng)作為實例,詳細(xì)分析了用C語言進(jìn)行CGI程序設(shè)計的方法與過程,隨著INTERET/INTRANET應(yīng)用的深入,將WEB與多臺數(shù)據(jù)庫聯(lián)接的需求也日益迫切,CGI可以使得WEB能夠能最低程序的復(fù)雜性與其后臺信息集成,成為一種支持多種類型的通用環(huán)境,但是由于在CGI方式中每執(zhí)行一次交互都需啟動一個外部程序,因此其在實時應(yīng)用方面受到了限制,因而,WEB SENER API及JOCBC等應(yīng)用方式也正在成熟.