送上来找人骂的程序
下午贴了一个,被各位高手骂了一通,小弟感激不尽。
请各位高手继续批评下面的用户注册程序,主要从:
1.编程风格
2.程序结构
3.有无错误
两个方面
#include <stdio.h>
#include <string.h>
struct stu_info
{
char UID[20];
int age;
char PWD[20];
};
int showMainMenu()
{
/* 显示主菜单并且返回用户的选择 */
int s;
printf("您要?\n");
printf("1.注册新用户\n");
printf("2.使用已经注册的用户名登陆\n");
while (s!=49 && s!=50)
{
s=getchar();
}
return s-48;
}
int checkUID(const char *UID)
{
/* 检查用户名的长度 将来会增加更多的检查条件 */
if (strlen(UID)<4 || strlen(UID)>10)
{
return 1;
}
else
{
return 0;
}
}
int checkPWD(const char *PWD, const char * confirmPWD)
{
/* 密码必须和确认密码箱等,这里没有直接返回strcmp的值是因为还要增加更多的密码验证条件 */
if (strcmp(PWD,confirmPWD)==0)
{
return 0;
}
else
{
return 1;
}
}
int regist()
{
struct stu_info newStudent;
char confirmPWD[20];
strcpy(newStudent.PWD,"");
newStudent.age=0;
strcpy(newStudent.UID,"");
while(checkUID(newStudent.UID)!=0)
{
printf("\n请输入您的姓名:");
scanf("%20s",newStudent.UID);
}
while (newStudent.age<5 || newStudent.age>100)
{
printf("\n请输入您的年龄:");
scanf("%d",&newStudent.age);
}
while (checkPWD(newStudent.PWD,confirmPWD)!=0)
{
printf("\n请输入您的密码:");
scanf("%s",&newStudent.PWD);
printf("请再次输入您的密码:");
scanf("%s",confirmPWD);
}
printf("\n注册已经完成...\n");
return 0;
}
void main()
{
int select=0;
select=showMainMenu(); /* 调用showMain函数显示菜单并返回用户的选择 */
switch (select)
{
case 1:
regist();
break;
default:
printf("Found error");
}
}