自学C语言 如下代码编译通过,可是运行时弹出:程序已停止工作。错哪了? 20
#include<stdio.h>intmain(){inta,b,c,d,e,f,g,i,len;charinstr[100];FILE*fp;fp=("d:\\xr1...
#include <stdio.h>
int main()
{
int a,b,c,d,e,f,g,i,len;
char instr[100];
FILE * fp;
fp=("d:\\xr1.txt","a");
scanf ("%d%d%d%d%d%d%d%s",&a,&b,&c,&d,&e,&f,&g,instr);
if (a%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (b%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (c%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (d%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (e%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (f%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (g%2==0)
fprintf(fp,"O ");
else
fprintf(fp,"X ");
len = strlen(instr);
for (i=0;i<len;i+=2)
if((instr[i]-'0')+(instr[i+1]-'0') <= 5)
fprintf(fp,"O");
else
fprintf(fp,"X");
fputc('\n',fp);
fclose(fp);
} 展开
int main()
{
int a,b,c,d,e,f,g,i,len;
char instr[100];
FILE * fp;
fp=("d:\\xr1.txt","a");
scanf ("%d%d%d%d%d%d%d%s",&a,&b,&c,&d,&e,&f,&g,instr);
if (a%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (b%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (c%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (d%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (e%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (f%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (g%2==0)
fprintf(fp,"O ");
else
fprintf(fp,"X ");
len = strlen(instr);
for (i=0;i<len;i+=2)
if((instr[i]-'0')+(instr[i+1]-'0') <= 5)
fprintf(fp,"O");
else
fprintf(fp,"X");
fputc('\n',fp);
fclose(fp);
} 展开
2个回答
展开全部
#include <stdio.h>
int main()
{
int a,b,c,d,e,f,g,i,len;
char instr[100];
FILE * fp;
fp=("d:\\xr1.txt","rw+");
if(fp==NULL)
{
printf("error!\n");
exit(0);
}
scanf ("%d%d%d%d%d%d%d%s",&a,&b,&c,&d,&e,&f,&g,instr);
if (a%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (b%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (c%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (d%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (e%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (f%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (g%2==0)
fprintf(fp,"O ");
else
fprintf(fp,"X ");
len = strlen(instr);
for (i=0;i<len;i+=2)
if((instr[i]-'0')+(instr[i+1]-'0') <= 5)
fprintf(fp,"O");
else
fprintf(fp,"X");
fputc('\n',fp);
fclose(fp);
}
int main()
{
int a,b,c,d,e,f,g,i,len;
char instr[100];
FILE * fp;
fp=("d:\\xr1.txt","rw+");
if(fp==NULL)
{
printf("error!\n");
exit(0);
}
scanf ("%d%d%d%d%d%d%d%s",&a,&b,&c,&d,&e,&f,&g,instr);
if (a%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (b%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (c%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (d%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (e%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (f%2==0)
fprintf(fp,"O");
else
fprintf(fp,"X");
if (g%2==0)
fprintf(fp,"O ");
else
fprintf(fp,"X ");
len = strlen(instr);
for (i=0;i<len;i+=2)
if((instr[i]-'0')+(instr[i+1]-'0') <= 5)
fprintf(fp,"O");
else
fprintf(fp,"X");
fputc('\n',fp);
fclose(fp);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询