为什么总是执行非法操作 ??
#include
#include
#include
/* void del(char str[])
{
int n,p,q,m;
n=strlen(str);
for (p=0;p {
while (str[p]!='\0')
{
for(q=p+1;q {
if(str[p]==str[q])
{
for(m=q;m str[m]=str[m+1];
}
}
}
}
}*/
char *delet(char *s,char x)
{int d,h;
char a[40];
strcpy(a,s);
for (d=0;d<{if (s[d]==x)
h=d;
}
s=s+h+1;
strcat(a,s);
return a;
}
int pphs(char x,char str[])
{
int g=0,h;
h=strlen(str);
for(;g {
if (x==str[g])
return 1;
}
return 0;
}
main()
{
int N,i,j=0,k=10;char *p;
char x;char str1[20];char str [6];
cout<<"猜数字游戏"< cout<<"请选择:"< cout<<"1:设置\n2:开始\n3:退出\n";
ofstream fout("cdc");
if (!fout)
{ cout<<"can not open output file \n";
return 1;}
fout <<"how";
fout.close();
ifstream fin("cdc");
if(!fin)
{cout<<"can not open input file\n";
return 1;}
fin >>str;
cout< fin.close();
strcpy(str1,str);
p=str1;
/*del(str1);*/
cin>>N;
switch(N)
{
case 1:cout<<" ---------"< break;
case 2:cout<<"你有"< cout<<" 次数:\n";
Mark: cin>>x;j++;
i=pphs(x,str1);
if(i==0)
{
cout<<"没有\n";
if(j==k)
cout<<"以达设定次数,未成功。失败!\n" ;
else if (j {
goto Mark;}
}
else if (i==1)
{ cout<<"有";
p=delet(str1,x);
if (j==k)
{
if(str1[0]=='\0')
cout<<"全部答对!答案:"< else
cout<<"以达设定次数,未成功。失败!\n";
}
if(i{
if(str1[0]=='\0')
cout<<"全部答对!答案:"< else
goto Mark;
}
}
break;
case 3:break;
case 4:break;
default:
cout <<"输入错误"< }
return 0;
}
--------------------next---------------------
阅读(1033) | 评论(0) | 转发(0) |