#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#include<conio.h>
struct user//個人資訊
{
char name[20];
char passward[20];
};
typedef struct wp//物品
{
char name[10];//名字
char number[10];//編號
char price[10];//價格
char classify[10];//分類
char scrq[20];//生產日期
char gqsj[20];//過期時間
struct wp *next;
}goods;
void newuser(void)//新用戶創建
{
char p[20];
int i=0;
FILE *fp;
printf("歡迎創建新賬戶\n");
struct user xin;
if((fp=fopen("usermassage.txt","a+"))==NULL)
{
printf("檔案打開失敗\n");
exit(0);
}
printf("請輸入新賬號:\n");
scanf("%s",xin.name);
printf("請輸入密碼:\n");
while((p[i]=getch())!='\r')
{
printf("*");
i++;
}
p[i]!='\0';
strcpy(xin.passward,p);
fprintf(fp,"%s %s\n",xin.name,xin.passward);
if(fclose(fp))
{
printf("檔案無法關閉\n");
exit(0);
}
printf("\n恭喜你成功創建新賬戶!\n");
}
int Denglu(char *mark)//用戶登錄
{
struct user xin;
int i=0,check=0;
FILE *fp;
char usr[30],usr1[30],mima[30],p[30];
printf("請輸入你的賬號名稱:");
scanf("%s",xin.name);
printf("請輸入賬戶密碼:");
while((p[i]=getch())!='\r')
{
printf("*");
i++;
}
p[i]='\0';
strcpy(xin.passward,p);
strcpy(usr,xin.name);
strcpy(mima,xin.passward);
strcat(usr," ");
strcat(usr,mima);
strcat(usr,"\n");
if((fp=fopen("usermassage.txt","r"))==NULL)
{
printf("檔案打開失敗\n");
exit(0);
}
while(!feof(fp))
{
fgets(usr1,30,fp);
if(strcmp(usr,usr1)==0)//用戶名與密碼相同
{
check=1;
break;
}
}
if(fclose(fp))
{
printf("關閉檔案失敗\n");
exit(0);
}
if(check==1)
{
printf("\n歡迎使用個人物品管理程式\n");//登陸成功
strcpy(mark,xin.name);
return 1;
}
else
{
printf("\n密碼或用戶名錯誤,請重新輸入\n");
return 0;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/80152.html
標籤:C語言
