|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
自学C语言第三天,写了一个登录注册系统
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- char ny;
- char usrname[256];
- char password[256];
- char password_sure[256];
- char u[256];
- char p[256];
-
- printf("欢迎使用用户注册登录系统!\n您要注册还是登录?\nY 注册 / N 登录\n");
- scanf("%c", &ny);
-
- if (ny == 'Y') //注册语句块
- {
- do
- {
- printf("请输入您要注册的用户名:\n");
- scanf("%s", usrname);
- printf("请输入您的密码:\n");
- scanf("%s", password);
- printf("请再次输入您要注册的密码:\n");
- scanf("%s", password_sure);
- if (0 == strcmp(password_sure, password)) //验证注册密码语句块
- {
- printf("注册成功,现在前往登陆\n");
- do //内嵌登录语句块
- {
- printf("请输入用户名:\n");
- scanf("%s", u);
- if (0 == strcmp(u, usrname))
- {
- do
- {
- printf("请输入密码:\n");
- scanf("%s", p);
- if (0 == strcmp(p, password))
- {
- printf("登录成功\n");
- }
- else
- {
- printf("输入错误\n");
- }
- }
- while (0 != strcmp(p, password));
- }
- else
- {
- printf("用户不存在!\n");
- }
- }
- while (0 != strcmp(u, usrname));
- }
- else //输入不一致的注册密码所执行的语句块
- {
- printf("两次输入的密码不一致,请再次注册!");
- }
- }
- while (0 != strcmp(password_sure, password));
- }
- else //登录语句块
- {
- printf("请输入用户名:\n");
- do
- {
- scanf("%s", u);
- if (0 == strcmp(u, usrname))
- {
- do
- {
- printf("请输入密码:\n");
- scanf("%s", p);
- if (0 == strcmp(p, password))
- {
- printf("登录成功\n");
- }
- else
- {
- printf("输入错误\n");
- }
- }
- while (0 != strcmp(p, password));
- }
- else
- {
- printf("用户不存在!\n");
- }
- }
- while (0 != strcmp(u, usrname));
- }
-
- printf("程序运行结束\n"); //检查是否正确结束了所有的 while 循环
-
- return 0;
- }
复制代码 |
评分
-
查看全部评分
|