#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char us[10];
char pa[10];
void signe();
void logi();
void get();
void put();
int main(int argc, const char * argv[])
{
printf("请选择注册还是直接登录,L登录,Z注册。");
char command = 'a';
rewind(stdin);
scanf("%c",&command);
switch(command)
{
case 'l':
logi();
break;
case 'z':
signe();
break;
default:
break;
}
return 0;
}
void get()
{
FILE *pUsers = fopen("/Users/hanqi/it/注册登录/users.txt","w");
FILE *pPass = fopen("/Users/hanqi/it/注册登录/password.txt","w");
printf("输入户名:\n");
char us[10];
fgets(us,10,stdin);
size_t real = strlen(us);
if(us[real-1] == '\n')
{
us[real-1] = '\0';
}
fputs(us,pUsers);
rewind(stdin);
printf("输入密码:\n");
char pa[10];
size_t realy = strlen(pa);
if(us[realy-1] == '\n')
{
us[realy-1] = '\0';
}
fgets(pa,10,stdin);
fputs(pa,pPass);
fclose(pPass);
fclose(pUsers);
}
void put()
{
FILE *pUsers = fopen("/Users/hanqi/it/注册登录/users.txt","r");
FILE *pPass = fopen("/Users/hanqi/it/注册登录/password.txt","r");
fgets(us,10,pUsers);
fgets(pa,10,pPass);
fclose(pPass);
fclose(pUsers);
}
void signe()
{
get();
put();
char nowUser[10];
char nowPass[10];
fgets(nowUser,10,stdin);
fgets(nowPass,10,stdin);
if(strcmp(us,nowUser) == 0 || strcmp(pa,nowPass) == 0)
{
printf("你输入的账户或密码已存在。");
return;
}
else
{
printf("注册成功。");
logi();
}
}
void logi()
{
get();
put();
char nowUser[10];
char nowPass[10];
fgets(nowUser,10,stdin);
fgets(nowPass,10,stdin);
if(strcmp(us,nowUser) == 0 || strcmp(pa,nowPass) == 0)
{
printf("登录成功");
return;
}
}
|
|