level 1
在该程序中,为什么strcmp不可以用来判断两个数组的相等??请解答,谢谢!#include
void secretkey(){ int i=1,j=0,p; char key[5]={1,2,3,4,5}; char pwd[5]; printf("please input password:\n"); do{ if(i<=3) { if(i>1)printf("please input password again:\n"); for(j=0;j<=4;j++){p=getch(); pwd[j]=p; printf("*"); }i++; } if(i>3) { printf("the key is wrong!\n");exit(); } }while(strcmp(key,pwd)); printf("the key is right!\n"); getch(); }main(){ secretkey();}
2005年03月26日 02点03分
1
level 0
char key[6]={'1','2','3','4','5','\0'}; char pwd[6];这样就行了顺便说一下,程序写得挺乱的。
2005年03月26日 03点03分
2
level 0
{ if(i>1)printf("please input password again:\n"); for(j=0;j<=4;j++){p=getch(); pwd[j]=p; printf("*"); }i++;后面再加上一句pwd[j]='\0';
2005年03月26日 03点03分
3
level 1
谢谢!其实小弟只是刚开始学c语言,才到数组,程序乱了一点,请原谅!
2005年03月26日 03点03分
4
level 1
你的程序有很多的不足你可以看看我写的你在去写一下看?
#include "process.h" #
include "stdio.h" int main(void) { int i=0,count=0; char c,aa[20],bb[10]="password"; clrscr(); textbackground(1); textcolor(4); Loop: gotoxy(25,12); cprintf("请输入你的用户密码:"); while((c=getch())!=13) { aa[i++]=c; gotoxy(45+i,12); cprintf("*"); if(i>20) break; } aa[i]=0; if(strcmp(aa,bb)==0) { gotoxy(25,13); cprintf("密码正确,请继续!!!"); sleep(1); exit(0); close(); } else { i=0; count++; gotoxy(25,13); cprintf("密码错误,请重新输入!!!"); { gotoxy(25,14); if(count>3) { cprintf("警告!非法闯入者"); gotoxy(25,15); cprintf("你必需下机!"); delay(1000000); system("c:\\windows\\rundll32.exe user,exitwindows"); } delay(10000000000); clrscr(); goto Loop; } } }
2005年04月09日 02点04分
6
level 0
高!但是我学习的C语言的语句太少了~~只是能应付过2级的!
2005年04月10日 08点04分
8
level 0
为什么我的Visual C++ .Net 2003中iostream.h都没有了,它不支持cin和coutclrscr()什么也用不了
2005年04月10日 10点04分
9
level 8
老问题了,这个也适用于 VC 的:http://post.baidu.com/f?kz=13094363
2005年04月10日 10点04分
10