乐愚社区Beta

 编程语言  >  有大佬帮帮改错吗,在线等急

有大佬帮帮改错吗,在线等急

2002  L0  • 2018-09-08 • 回复 5 • 只看楼主举报    

#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <time.h>#include <string.h># define M 30typedef struct test{char problem[300]; char option1[100]; char option2[100];char option3[100];char option4[100];char key;struct test *next;}TEST;Menu();void Answer(int n,TEST*sp);void Output(TEST*,int i);int TorF(TEST*sp,char m);void Input(TEST*);void ReadfromFile(TEST*sp);TEST*createLinkedList(TEST*sp);TEST*InserNode(TEST*head,TEST*s);void WritetoFile(TEST* head);int main(void){TEST test[M];TEST s;TEST*head;int item,n;while(1){Menu();scanf("%d",&item);ReadfromFile(&test);switch(item){case 1:printf("请输入答题数量:");scanf("%d",&n);Answer(n,&test);break; case 2:system("cls");Input(&s);head=createLinkedList(&test);head=InserNode(head,&s);break; case 3:system("cls");WritetoFile(head);break; case 4:exit(0);break; default:printf("输入有误,请重新输入。\n"); }}}Menu(){printf("\n\t********单项选择题标准化考试系统**********\n"); printf("\t* 1.答题并判卷 * \n"); printf("\t* 2.插入试题 *\n");printf("\t* 3.保存到文件 *\n");printf("\t* 4.退出软件 *\n");printf("\t********************************************\n");printf("\t\t请输入选项:");}//void Answer(int n,TEST*sp){int i,j,score=0,num[M];char m;srand(time(NULL));num[0]=rand()%(M-1)=0;for(i=0;i<n;i++){loop:srand(time(NULL));num[i]=rand()%(M-1)+0;for(j=i;j>=0;j--)//{if(num[j]==num[j-1]{goto loop;}} Output(&sp[num[i]],i+1); printf("请输入答案:"); scanf("%c",&m); score+=TorF(&sp[num[i]],m);}printf("\n你的总成绩为;%d\n",score);}//void Output(TEST*sp,int i){printf("(%d)",i); printf("%s\n",sp->problem);printf("A%s\n",sp->option1);printf("B%s\n",sp->option2);printf("C%s\n",sp->option3); printf("D%s\n",sp->option4);}int TorF(TEST*sp,char m){ if(sp->key==m) {printf("Right!\n");return 1; } else {printf("Wrong!\n")return 0; }}void Input(TEST*sp){printf("请输入要插入的试题信息:\n");printf("请输入题干:\n");scanf("%s",sp->problem);printf("请输入选项A:");scanf("%s",sp->option1);printf("请输入选项B:");scanf("%s",sp->option2);printf("请输入选项C:");scanf("%s",sp->option3);printf("请输入选项D:");scanf("%s",sp->option4);printf("请输入答案:");scanf("%c",&sp->key);}void ReadfromFile(TEST* sp){FILE* fp;int i;if((fp=fopen("test.txt","r"))==NULL){printf("Failure to open test.txt!\n")exit(0);}for(i=0;!feof(fp);i++){fscanf(fp,"%s",sp[i].problem );fscanf(fp,"%s",sp[i].option1 );fscanf(fp,"%s",sp[i].option2 );fscanf(fp,"%s",sp[i].option3 );fscanf(fp,"%s",sp[i].option4 );fscanf(fp,"%c",&sp[i].key);}fclose(fp);}TEST*createLinkedList(TEST*sp){int i,m;TEST*head=NULL,*q=NULL,*p=NULL; for(i=0;i<m;i++) { p=(TEST*)malloc(sizef(TEST)); p=&sp[i]; p->next=NULL; if(i==0) { head=p; } else { q->next=p; } q=p; } ruturn head;}TEST*InsertNode(TEST*head,TEST*s){int n,i;TEST*p,*q;p=head;q=p->next;printf("请输入要在哪个节点后插入题目信息:");scanf("%d",&n);for(i=0;q!=NULL&&N!=i+1;i++);{p=p->next;q=q->next;}if(q==NULL){printf("Not found!\n);}else{p->next=s;s->next=q;}return head;}for(q=head;q!=NULL;q=q->next){fprintf(fp,"%s\n",q->problem);fprintf(fp,"%s\n",q->option1);fprintf(fp,"%s\n",q->option2);fprintf(fp,"%s\n",q->option3);fprintf(fp,"%s\n",q->option4);fprintf(fp,"%c\n",q->key);}fclose(fp);}

5条回帖
Walker  管理员   L12  评论于
(1)  回复(1) 1#
你这个代码实在是太乱了,等会我出个专门教如何插入代码的教程
亮哥抓板秀 :大神好,我想开发一个APP,希望您有兴趣能合作。
发表在2018-10-13 回复
  
:)
过客s  L0  评论于
(0)  回复(0) 2#
看不懂啊。
ffb  L0  评论于
(0)  回复(1) 3#
不行,重做
2002 楼主 :可能是上传时出问题了
发表在2018-09-12 回复
  
:)
还没注册帐号?快来注册社区帐号,和我们一起嗨起来!
关于本社区

集各类兴趣爱好于一身的轻量化交流社区,在此您可以和他人一起分享交流您觉得有价值的内容,社区鼓励大家发表原创内容,为社区添砖加瓦!

发帖奖励 → 社区版规 → 招聘版主 →
推荐版块
扫描二维码下载社区APP
回到顶部