Home > Back-end >  C language file input garbled words problem (code is not complete)
C language file input garbled words problem (code is not complete)

Time:09-27

#include
#include
#include
#include
#include
Struct user//personal information
{
char name[20];
Char passward [20].
};
Typedef struct wp/items/
{
Char name [10].//name
Char number [10].//number
Char price [10].//price
Char classify [10].//classification
Char SCRQ [20].//production date
Char GQSJ [20].//expiration time
Struct wp * next;
} goods;

Void newuser (void)//new users to create
{
Char [20] p;
int i=0;
FILE *fp;
Printf (" welcome to create a new account \ n ");
Struct user xin;
If ((fp=fopen (" usermassage. TXT ", "a +"))==NULL)
{
Printf (" file open failed \ n ");
exit(0);
}
Printf (" please enter a new account: \ n ");
The scanf (" % s ", xin. Name);
Printf (" please enter the password: \ n ");
While ((p=[I] getch ())!='\ r')
{
Printf (" * ");
i++;
}
P [I]!='\ 0';
Strcpy (xin. The passward, p);
Fprintf (fp, "% s % s \ n", xin. The name, xin. The passward);
If (fclose (fp))
{
Printf (" file cannot be closed \ n ");
exit(0);
}
Printf (" \ n congratulations on your success to create a new account! \n");
}

Int Denglu (char * mark)//user logs in
{
Struct user xin;
Int I=0, check=0;
FILE *fp;
Usr1 char usr [30], [30], mima [30], [30] p;
Printf (" please input your account name: ");
The scanf (" % s ", xin. Name);
Printf (" please enter the account password: ");
While ((p=[I] getch ())!='\ r')
{
Printf (" * ");
i++;
}
P [I]='\ 0';
Strcpy (xin. The passward, p);
Strcpy (usr, xin. Name);
Strcpy (mima, xin. The passward);
Strcat (usr, "");
Strcat (usr mima);
Strcat (usr, "\ n");
If ((fp=fopen (" usermassage. TXT ", "r"))==NULL)
{
Printf (" file open failed \ n ");
exit(0);
}
while(! The feof (fp))
{
The fgets (usr1, 30, fp);
If (STRCMP (usr, usr1)==0)//the same user name and password
{
Check=1;
break;
}
}
If (fclose (fp))
{
Printf (" failed to close file \ n ");
exit(0);
}
If (check==1)
{
Printf (" \ n \ n welcome to use personal items management program ");//landing successful
Strcpy (mark, xin. Name);
return 1;
}
The else
{
Printf (" \ n your user name or password error, please input again \ n ");
return 0;
}
}
  • Related