比如这个程序吧
没报错 但是没能出结果
能帮忙改改吗??
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void makecst1(FILE *fp)
{
int a,b,i;
char op;
for (i = 0; i < 10; i++) {
switch(rand()%4) {
case 0:op='+';break;
case 1:op='-';break;
case 2:op='*';break;
case 3:op='/';break;
}
if (op=='/') {
a=rand()%90+10;
b=(rand()%90+10)%a+1;
b=a/b;
a=(a/b)*b;
}
else{
a=rand()%90+10;
b=rand()%90+10;
}
fprintf(fp,"%d%c%d\n",a,op,b);
}
}
void makecst1an(FILE *fp1,FILE *fp2)
{
int a,b,c;
char op;
while (!feof(fp1))
{
fscanf(fp1,"%d%c%d\n",&a,&op,&b);
switch (op) {
default:
case '+':c=a+b;break;
case '-':c=a-b;break;
case '*':c=a*b;break;
case '/':c=a/b;break;
}
fprintf(fp2,"%d%c%d=%d\n",a,op,b,c);
}
}
int main(void)
{
FILE *fp1,*fp2;
srand(time(0));
fp1=fopen("d:\\abc\\cst1.dat","w+");
if (fp1) {
makecst1(fp1);
rewind(fp1);
fp2=fopen("d:\\abc\\cst1_an.dat","w");
if (fp2) makecst1an(fp1,fp2);
fclose(fp1);
fclose(fp2);
}
return 0;
}