代码文本:
#include "stdio.h"
#include "time.h"
int main(int argc,char *argv[]){
char s[19]
int y,t,ty
time_t lt
printf("Please enter your ID number...\n")
if(scanf("%18s",s)==1){
for(t=0s[t]t++)
if(t==18){
for(t=0s[t]t++)
if((s[t]<'0' || s[t]>'9') &&(s[17]&0xDF)!='X'){
printf("Input error, exit...\n")
return 0
}
sscanf(s+6,"%4d",&y)
printf("\nThe year %d you were born is ",y)
if(!(y%4==0 &&y%100 || y%400==0))
printf("not ")
ty=localtime(&(lt=time(NULL)))->tm_year+1900-y
printf("a leap year.\nYou're %d year(s) old...\n",ty)
}
else
printf("Input error, exit...\n")
}
else
printf("Input failed, exit...\n")
return 0
}
输入数据那块:for(i=0i<10i++)
{
printf("enter the name and the score:")
scanf("%f,%s",&score[i],name[i])
}
你写的先输入名字后输分数, 而你读取时是先读分数 后读名字
这里可能是你出错的原因之一
还有就是最好不要在scanf()读取时有逗号出现就像下面这句:
scanf("%f,%s",&score[i],name[i])
如果这里两个格式控制符中间有逗号 当你输入时也要在两个输入的变量之间加上逗号, 并且当你输入的时候输入的是中文状态下的逗号时 就会出错.
你再试试吧, 应该没问题了