1 以字符串方式,读入用户名和密码;
2 通过strcmp函数,判断是否相同。如相同,则合法。
3 给出提示信息。
说明:strcmp原型为
int strcmp(char *a, char *b);
功能为比较a和b两个字符串,如果相同返回0;如果a大返回1;如果b大返回-1。
大小依照ascii比较。
参考代码如下:
#include
#include
int main()
{
char a[100],b[100];
scanf("%s%s",a,b);
if(strcmp(a,"abc") == 0 && strcmp(b, "123456") == 0)
printf("用户合法\n");
else printf("用户非法\n");
}
楼上的,你没进错。。不过语言是通用的。。
附楼主要的代码。
#include
#include
void main()
{
int i=0;
while(i<3)
{
printf( "输入用户名:");
char name[10],psw[10];
scanf("%s",name);
printf("输入密码:");
scanf("%s",psw);
if((strcmp(name,"abc")==0)&&(strcmp(psw,"123456"))==0)
{
printf("welcome to use the software\n");
break;
}
i++;
}
if(i>=3)
{
printf("password error!you can not use software\n");
}
}
楼下的,我没进错专区吧?