C语言-用户登录系统界面
程序员文章站
2022-03-22 23:01:40
...
运行程序时,指定用户名,不输入,或少输入,或输入错误,都提示用户不同的错误,并退出程序。
用户名正确:开始输入密码(要求错误后能多次输入,循环)。
密码输入错误:重新输入(错误5次结束程序)。
输入正确:打印欢迎用户!
更多资料请点击:我的目录
运行时输入用户名与密码:
#include <stdio.h>
#include <string.h>
int main(int argc , const char **argv)
{
char name[10];
char word[10];
char username[10] = "jiajia";
char password[10] = "jiajia";
int n;
printf("\n\n");
printf("\t*******************************\n");
printf("\t********* 用户登录系统 *********\n");
printf("\t*******************************\n");
printf("\n\n");
printf("\tPlease enter username.\n");
printf("\tusername:");
scanf("%s",name);
printf("\n");
if( strcmp(username , name) == 0)
{
printf("\tPlease enter password.\n");
printf("\tpassword:");
scanf("%s",word);
for(n = 0; n < 5; n++)
{
if( strcmp( password , word) == 0 )
{
printf("\n\n");
printf("\t*******************************\n");
printf("\t********* 欢迎用户! *********\n");
printf("\t*******************************\n");
printf("\n\n");
break;
}
else
{
printf("\tPlease enter again!\n");
printf("\tpassword:");
scanf("%s",word);
if( strcmp( password , word) == 0 )
{
printf("\n\n");
printf("\t*******************************\n");
printf("\t********* 欢迎用户! *********\n");
printf("\t*******************************\n");
printf("\n\n");
break;
}
}
}
}
else if( strlen( name ) < 6)
{
printf("\tLess input!\n");
}
else if( strcmp(username , name) != 0)
{
printf("\tUsername error! Please enter again!\n");
}
return 0;
}
基于Linux系统shell输入:(需要在运行前输入用户名)
#include <stdio.h>
#include <string.h>
int main(int argc , const char **argv)
{
char username[10] = "jiajia";
char password[10] = "jiajia";
char word[10];
int n;
printf("\n\n");
printf("\t*******************************\n");
printf("\t********* 用户登录系统 *********\n");
printf("\t*******************************\n");
printf("\n\n");
if( strcmp(username , argv[1]) == 0)
{
printf("\tUsername:\t%s\n",argv[1]);
printf("\tPlease enter password.\n");
printf("\tPassword:\t");
scanf("%s",word);
for(n = 0; n < 5; ++n)
{
if( strcmp( password , word) == 0 )
{
printf("\n\n");
printf("\t*******************************\n");
printf("\t********* 欢迎用户! *********\n");
printf("\t*******************************\n");
printf("\n\n");
break;
}
else
{
printf("\n\tPlease enter again!\n");
printf("\tpassword:\t");
scanf("%s",word);
if( strcmp( password , word) == 0 )
{
printf("\n\n");
printf("\t*******************************\n");
printf("\t********* 欢迎用户! *********\n");
printf("\t*******************************\n");
printf("\n\n");
break;
}
}
}
}
else if( strlen( argv[1] ) < 6)
{ printf("\tUsername:\t%s\n",argv[1]);
printf("\tLess input!\n");
}
else if( strcmp(username , argv[1]) != 0)
{ printf("\tUsername:\t%s\n",argv[1]);
printf("\tPlease enter again!\n");
}
return 0;
}
更多资料请点击:我的目录
上一篇: python如何做excel自动化