请求大佬们救救孩子!程序今晚就要交了,运行到选择试题之后程序却结束了
#include<stdio.h>#include<stdlib.h>
#define LEN sizeof(struct Test)
void getInput(struct Test *test);
int put_test(int m);
void testing();
int total(void);
void remain();
void main();
struct Test
{
char que;
char answer1;
char answer2;
char answer3;
char answer4;
char ture;
struct Test *next;
};
struct Test *head;
int put_test(int m)
{
struct Test *test=NULL;
FILE *fp;
if((fp=fopen("test1.txt","r"))==NULL)
{
printf("打开文件失败!\n");
exit(0);
}
char ch,ture_answer;
int i,n=0,now,py;
do
{
py=1;
ch=fgetc(fp);
for(i=0;ch!='\n'&&ch!=-1;i++)
{
py++;
ch=fgetc(fp);
}
n++;
if(n==m)
{
if(test==NULL)
{
test=(struct Test *)malloc(LEN);
head=test;
test->next=NULL;
}
else
{
test->next=test;
test=(struct Test *)malloc(LEN);
test->next=NULL;
}
now=ftell(fp);
fseek(fp,(now-py-1),0);
fscanf(fp,"%s%s%s%s%s%s",&test->que,&test->answer1,&test->answer2,&test->answer3,&test->answer4,&ture_answer);
fseek(fp,now+1,0);
*test->ture=ture_answer;
break;
}
}while(!feof(fp));
fclose(fp);
return 0;
}
void testing()
{
int n,o_n,m,i,yes=0,no=0;
char user_answer;
struct Test *test;
printf("请输入您想答题的数目:\n");
scanf("%d",&n);
o_n=total();
if(n>o_n||n<0)
{
printf("输入错误!");
testing();
}
for(i=0;i<n;i++)
{
do
{
m=rand();
}while(m<=0&&m>o_n);
put_test(m);
test=head;
printf("第%d题:\n",i+1);
printf("%s\n%s\n%s\n%s\n%s\n请输入您的答案:",*test->que,*test->answer1,*test->answer2,*test->answer3,*test->answer4);
scanf("%s",&user_answer);
if(user_answer==*test->ture)
{
printf("答案正确!");
yes++;
}
else
{
printf("答案错误!\n正确答案是:%s\n",test->ture);
no++;
}
}
test=head;
do
{
head=test->next;
free(test);
test=head;
}while(test!=NULL);
printf("测试结束!\n您的得分是:%d\n正确率:%.2f%%\n",yes,(float)yes/n*100);
remain();
}
int total(void)
{
FILE *fp;
if((fp=fopen("test1.txt","r"))==NULL)
{
printf("打开文件失败!");
exit(0);
}
int n=0;
char c;
c=fgetc(fp);
do
{
if(c=='\n')
n++;
c=fgetc(fp);
}while(!feof(fp));
return n;
}
void getInput(struct Test *test)
{
int i,n;
printf("你将输入多少道试题?\n");
scanf("%d",&n);
FILE *fp;
if((fp=fopen("test1.txt","a"))==NULL)
{
printf("打开文件错误!\n");
exit(0);
}
test=(struct Test *)malloc(LEN);
for(i=1;i<=n;i++)
{
printf("题目:");
scanf("%s",test->que);
printf("A.");
scanf("%s",test->answer1);
printf("B.");
scanf("%s",test->answer2);
printf("C.");
scanf("%s",test->answer3);
printf("D.");
scanf("%s",test->answer4);
printf("正确答案:");
scanf("%s",test->ture);
fputs(test->que,fp);
fputs(" A.",fp);
fputs(test->answer1,fp);
fputs(" B.",fp);
fputs(test->answer2,fp);
fputs(" C.",fp);
fputs(test->answer3,fp);
fputs(" D.",fp);
fputs(test->answer4,fp);
fputs(" 正确答案:",fp);
fputs(test->ture,fp);
fputc('\n',fp);
}
fclose(fp);
free(test);
remain();
}
void remain()
{
int flag;
printf("1.返回主菜单\n");
printf("2.退出程序\n");
printf("请输入你的选择:\n");
scanf("%d",&flag);
switch(flag)
{
case 1: main(); break;
case 2: exit(0);break;
default:printf("输入错误!");
}
}
void main()
{
struct Test test;
int flag;
printf("--------单项选择题标准化考试系统--------\n");
printf("1.录入试题\n");
printf("2.自主测试\n");
printf("3.退出程序\n");
printf("请输入你的选择:\n");
scanf("%d",&flag);
switch(flag)
{
case 1: getInput(&test); break;
case 2: testing(); break;
case 3: exit(0); break;
default:printf("输入错误!\n");
}
}
具体描述一下你这个程序的问题
我需要 这个程序的每一步操作,直到出现问题
首先运行这个程序,然后输入 1 ?
然后输入什么?
反正就是你一直输入,直到发现了明显的问题为止
我要全部的这些输入 加油 加油
人造人 发表于 2021-6-22 22:25
具体描述一下你这个程序的问题
我需要 这个程序的每一步操作,直到出现问题
首先运行这个程序,然后输入...
输入完1之后开始设置几个题目,输入题目的个数之后输入题目的内容以及选项、正确答案;第二个程序是自主测试,选择自主测试之后输入你想测试题目的题号 Gacy 发表于 2021-6-22 22:42
加油
哈哈哈哈?喵喵喵? 人造人 发表于 2021-6-22 22:25
具体描述一下你这个程序的问题
我需要 这个程序的每一步操作,直到出现问题
首先运行这个程序,然后输入...
运行以后结果成这样:
--------单项选择题标准化考试系统--------
1.录入试题
2.自主测试
3.退出程序
请输入你的选择:
1
你将输入多少道试题?
2
题目:2
A.1
B.1
C.2
D.3
正确答案:C
题目:3
A.1
B.23
C.3
D.4
正确答案:C
1.返回主菜单
2.退出程序
请输入你的选择:
2
--------------------------------
Process exited after 20.65 seconds with return value 0
请按任意键继续. . . 小菜鸡溜溜达 发表于 2021-6-22 23:09
运行以后结果成这样:
--------单项选择题标准化考试系统--------
1.录入试题
如果你的编译器什么提示也没有的话,一定要换一个好点的
main.c:5:22: warning: ‘struct Test’ declared inside parameter list will not be visible outside of this definition or declaration
5 | void getInput(struct Test *test);
| ^~~~
main.c: In function ‘put_test’:
main.c:61:29: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘char (*)’ [-Wformat=]
61 | fscanf(fp,"%s%s%s%s%s%s",&test->que,&test->answer1,&test->answer2,&test->answer3,&test->answer4,&ture_answer);
| ~^ ~~~~~~~~~~
| | |
| char * char (*)
main.c:61:31: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘char (*)’ [-Wformat=]
61 | fscanf(fp,"%s%s%s%s%s%s",&test->que,&test->answer1,&test->answer2,&test->answer3,&test->answer4,&ture_answer);
| ~^ ~~~~~~~~~~~~~~
| | |
| char * char (*)
main.c:61:33: warning: format ‘%s’ expects argument of type ‘char *’, but argument 5 has type ‘char (*)’ [-Wformat=]
61 | fscanf(fp,"%s%s%s%s%s%s",&test->que,&test->answer1,&test->answer2,&test->answer3,&test->answer4,&ture_answer);
| ~^ ~~~~~~~~~~~~~~
| | |
| char * char (*)
main.c:61:35: warning: format ‘%s’ expects argument of type ‘char *’, but argument 6 has type ‘char (*)’ [-Wformat=]
61 | fscanf(fp,"%s%s%s%s%s%s",&test->que,&test->answer1,&test->answer2,&test->answer3,&test->answer4,&ture_answer);
| ~^ ~~~~~~~~~~~~~~
| | |
| char * char (*)
main.c:61:37: warning: format ‘%s’ expects argument of type ‘char *’, but argument 7 has type ‘char (*)’ [-Wformat=]
61 | fscanf(fp,"%s%s%s%s%s%s",&test->que,&test->answer1,&test->answer2,&test->answer3,&test->answer4,&ture_answer);
| ~^ ~~~~~~~~~~~~~~
| | |
| char * char (*)
main.c:61:39: warning: format ‘%s’ expects argument of type ‘char *’, but argument 8 has type ‘char (*)’ [-Wformat=]
61 | fscanf(fp,"%s%s%s%s%s%s",&test->que,&test->answer1,&test->answer2,&test->answer3,&test->answer4,&ture_answer);
| ~^ ~~~~~~~~~~~~
| | |
| char * char (*)
main.c: In function ‘testing’:
main.c:93:26: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
93 | printf("%s\n%s\n%s\n%s\n%s\n请输入您的答案:",*test->que,*test->answer1,*test->answer2,*test->answer3,*test->answer4);
| ~^ ~~~~~~~~~~
| | |
| char * int
| %d
main.c:93:30: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat=]
93 | printf("%s\n%s\n%s\n%s\n%s\n请输入您的答案:",*test->que,*test->answer1,*test->answer2,*test->answer3,*test->answer4);
| ~^ ~~~~~~~~~~~~~~
| | |
| char * int
| %d
main.c:93:34: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat=]
93 | printf("%s\n%s\n%s\n%s\n%s\n请输入您的答案:",*test->que,*test->answer1,*test->answer2,*test->answer3,*test->answer4);
| ~^ ~~~~~~~~~~~~~~
| | |
| char * int
| %d
main.c:93:38: warning: format ‘%s’ expects argument of type ‘char *’, but argument 5 has type ‘int’ [-Wformat=]
93 | printf("%s\n%s\n%s\n%s\n%s\n请输入您的答案:",*test->que,*test->answer1,*test->answer2,*test->answer3,*test->answer4);
| ~^ ~~~~~~~~~~~~~~
| | |
| char * int
| %d
main.c:93:42: warning: format ‘%s’ expects argument of type ‘char *’, but argument 6 has type ‘int’ [-Wformat=]
93 | printf("%s\n%s\n%s\n%s\n%s\n请输入您的答案:",*test->que,*test->answer1,*test->answer2,*test->answer3,*test->answer4);
| ~^ ~~~~~~~~~~~~~~
| | |
| char * int
| %d
main.c:94:25: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)’ [-Wformat=]
94 | scanf("%s",&user_answer);
| ~^~~~~~~~~~~~~
| ||
| |char (*)
| char *
main.c: At top level:
main.c:137:6: error: conflicting types for ‘getInput’; have ‘void(struct Test *)’
137 | void getInput(struct Test *test)
| ^~~~~~~~
main.c:5:6: note: previous declaration of ‘getInput’ with type ‘void(struct Test *)’
5 | void getInput(struct Test *test);
| ^~~~~~~~
main.c:197:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
197 | void main()
| ^~~~
#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct Test)
//void getInput(struct Test *test);
int put_test(int m);
void testing();
int total(void);
void remain();
//void main();
int main(void);
struct Test
{
char que;
char answer1;
char answer2;
char answer3;
char answer4;
char ture;
struct Test *next;
};
struct Test *head;
void getInput(struct Test *test);
int put_test(int m)
{
struct Test *test=NULL;
FILE *fp;
if((fp=fopen("test1.txt","r"))==NULL)
{
printf("打开文件失败!\n");
exit(0);
}
char ch,ture_answer;
int i,n=0,now,py;
do
{
py=1;
ch=fgetc(fp);
for(i=0;ch!='\n'&&ch!=-1;i++)
{
py++;
ch=fgetc(fp);
}
n++;
if(n==m)
{
if(test==NULL)
{
test=(struct Test *)malloc(LEN);
head=test;
test->next=NULL;
}
else
{
test->next=test;
test=(struct Test *)malloc(LEN);
test->next=NULL;
}
now=ftell(fp);
fseek(fp,(now-py-1),0);
//fscanf(fp,"%s%s%s%s%s%s",&test->que,&test->answer1,&test->answer2,&test->answer3,&test->answer4,&ture_answer);
fscanf(fp,"%s%s%s%s%s%s",test->que,test->answer1,test->answer2,test->answer3,test->answer4,ture_answer);
fseek(fp,now+1,0);
*test->ture=ture_answer;
break;
}
}while(!feof(fp));
fclose(fp);
return 0;
}
void testing()
{
int n,o_n,m,i,yes=0,no=0;
char user_answer;
struct Test *test;
printf("请输入您想答题的数目:\n");
scanf("%d",&n);
o_n=total();
if(n>o_n||n<0)
{
printf("输入错误!");
testing();
}
for(i=0;i<n;i++)
{
do
{
m=rand();
}while(m<=0&&m>o_n);
put_test(m);
test=head;
printf("第%d题:\n",i+1);
//printf("%s\n%s\n%s\n%s\n%s\n请输入您的答案:",*test->que,*test->answer1,*test->answer2,*test->answer3,*test->answer4);
printf("%s\n%s\n%s\n%s\n%s\n请输入您的答案:",test->que,test->answer1,test->answer2,test->answer3,test->answer4);
//scanf("%s",&user_answer);
scanf("%s",user_answer);
if(user_answer==*test->ture)
{
printf("答案正确!");
yes++;
}
else
{
printf("答案错误!\n正确答案是:%s\n",test->ture);
no++;
}
}
test=head;
do
{
head=test->next;
free(test);
test=head;
}while(test!=NULL);
printf("测试结束!\n您的得分是:%d\n正确率:%.2f%%\n",yes,(float)yes/n*100);
remain();
}
int total(void)
{
FILE *fp;
if((fp=fopen("test1.txt","r"))==NULL)
{
printf("打开文件失败!");
exit(0);
}
int n=0;
char c;
c=fgetc(fp);
do
{
if(c=='\n')
n++;
c=fgetc(fp);
}while(!feof(fp));
return n;
}
void getInput(struct Test *test)
{
int i,n;
printf("你将输入多少道试题?\n");
scanf("%d",&n);
FILE *fp;
if((fp=fopen("test1.txt","a"))==NULL)
{
printf("打开文件错误!\n");
exit(0);
}
test=(struct Test *)malloc(LEN);
for(i=1;i<=n;i++)
{
printf("题目:");
scanf("%s",test->que);
printf("A.");
scanf("%s",test->answer1);
printf("B.");
scanf("%s",test->answer2);
printf("C.");
scanf("%s",test->answer3);
printf("D.");
scanf("%s",test->answer4);
printf("正确答案:");
scanf("%s",test->ture);
fputs(test->que,fp);
fputs(" A.",fp);
fputs(test->answer1,fp);
fputs(" B.",fp);
fputs(test->answer2,fp);
fputs(" C.",fp);
fputs(test->answer3,fp);
fputs(" D.",fp);
fputs(test->answer4,fp);
fputs(" 正确答案:",fp);
fputs(test->ture,fp);
fputc('\n',fp);
}
fclose(fp);
free(test);
remain();
}
void remain()
{
int flag;
printf("1.返回主菜单\n");
printf("2.退出程序\n");
printf("请输入你的选择:\n");
scanf("%d",&flag);
switch(flag)
{
case 1: main(); break;
case 2: exit(0);break;
default:printf("输入错误!");
}
}
//void main()
int main(void)
{
struct Test test;
int flag;
printf("--------单项选择题标准化考试系统--------\n");
printf("1.录入试题\n");
printf("2.自主测试\n");
printf("3.退出程序\n");
printf("请输入你的选择:\n");
scanf("%d",&flag);
switch(flag)
{
case 1: getInput(&test); break;
case 2: testing(); break;
case 3: exit(0); break;
default:printf("输入错误!\n");
}
return 0;
}
人造人 发表于 2021-6-22 23:38
太太太感谢了!!!!!! 小菜鸡溜溜达 发表于 2021-6-22 23:07
哈哈哈哈?喵喵喵?
现在人还“健在”吧{:10_256:}啊哈哈哈 Gacy 发表于 2021-6-23 10:15
现在人还“健在”吧啊哈哈哈
还健在啊哈哈
页:
[1]