#include <stdio.h>
//#define sz1 "hello"
int main(int argc, char *argv[])
{
//char sz1[8] = "hello";
//const char *sz1 = "hello";
char sz1[8];
char sz2[8];
memset(sz1,0x00,sizeof(sz1));
strcpy(sz1,"hello");
printf("sz1=[%s]\n",sz1);
while(1)
{
memset(sz2,0x00,sizeof(sz2));
printf("please input passwd:\n");
//gets(sz2);
scanf("%s",sz2);
//fgets(sz2,sizeof(sz2),stdin);
printf("---sz1=[%s]\n",sz1);
printf("---sz2=[%s]\n",sz2);
if(0 == strcmp(sz1,sz2))
{
printf("----hello world-----\n");
break;
}
else
{
printf("----ERROR----\n");
continue;
}
}
return 0;
}
-----------------测试结果---------------
sz1=[hello]
please input passwd:
12345678ayang
---sz1=[ayang]
---sz2=[12345678ayang]
----ERROR----
please input passwd:
hello
---sz1=[ayang]
---sz2=[hello]
----ERROR----
please input passwd:
ayang
---sz1=[ayang]
---sz2=[ayang]
----hello world-----
转载于:https://blog.51cto.com/ayang/1652787