newrecord.c
来自「比较原始的学校出题系统」· C语言 代码 · 共 45 行
C
45 行
void newRecord(FILE * fPtr)
{
char y_n;
struct examination ex3;
int acctNum;
bingo1:
printf("Enter new 试题编号(1~100): ?");
scanf("%d",&acctNum);
fseek(fPtr,(acctNum - 1)*sizeof(struct examination),SEEK_SET);
fread(&ex3,sizeof(struct examination),1,fPtr);
if(ex3.acctNum != 3)
{
printf("编号 # %d already contains information.\n",acctNum);
}
else
{
printf("Enter 试题内容(<100 bytes) :?");
scanf("%s",ex3.content);
printf("Enter 试题答案(<10 bytes) :?");
scanf("%s",ex3.answer);
printf("Enter 试题题型(1~3) :?");
scanf("%d",&ex3.type);
while(ex3.type!=1||ex3.type!=2||ex3.type!=3)
{
printf("输入有误,请重输");
scanf("%d",&ex3.type);
}
printf("Enter 试题知识点(1~15) :?");
scanf("%d",ex3.knowledge);
while(ex3.knowledge<1||ex3.knowledge>15)
{
printf("输入有误,请重输");
scanf("%d",&ex3.knowledge);
}
ex3.acctNum = acctNum;
fseek(fPtr,(ex3.acctNum - 1)*sizeof(struct examination),SEEK_SET);
fwrite(&ex3,sizeof(struct examination),1,fPtr);
printf("添加成功!");
}
printf("是否继续添加?(Y/N)");
y_n = getch();
printf("%c",y_n);
if(y_n == 'y')
goto bingo1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?