为什么c语言密码设置不成功

来源:百度知道 编辑:UC知道 时间:2024/05/29 23:27:21
/*installing intrenet assistant*****the code is "wangyaochuan"****/
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char code[12],char incode[12]={"wangyaochuan"};
int i=1,he;
for(;i<=3;i++)
{
printf("please input the password:");
gets(code);
he=strcmp(code,incode);/*为什么只要把incode改为"wangyaochuan"即可密码设置成功*/
if(he==0) break;
if(i==3){puts("sorry, you can't enter the program!") ; return;}
}
printf("the result is %d",i);
}(我的分不多,请大家见谅!!!在此多谢)

char incode[12]={"wangyaochuan"}; 长度不够,你忘了字符串后面有‘\0’的……

code[13],char incode[13]

试试
"wangyaochuan"后面会有一个'\0'

#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char code[20], incode[]={"wangyaochuan"}; ///////////////////////////
int i=1,he;
for(;i<=3;i++)
{
printf("please input the password:");
gets(code);
he=strcmp(code,incode);/*?什么只要把incode改?"wangyaochuan"即可密??置成功*/
if(he==0) break;
if(i==3){puts("sorry, you can't enter the program!") ; return;}
}
printf("the result is %d",i);
}

不光是incode要设长度为13,code也要设为13