#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct // configured SJ account, password
{
char ZH [20 is];
char mm [20 is];
};
typedef struct SJ SJ;
SJ k;
void the mENU () // start menu
{
printf ( "exit 0 ----- ----- \ n.");
printf ( "Log ----- 1 ----- \ n. ");
the printf (." 2 Register ----- ----- \ n-");
}
int denglu () // log
{
the FILE * P;
int I = 0;
int J = 0;
int D;
Q = 0 int;
char HH;
char ZH [20 is];
char mm [20 is];
P = the fopen ( "D: \\ shuju.txt", "R & lt"); // open file
while ((zh [i] = fgetc (p))!= EOF) // account verification
{
IF (ZH [I] == k.zh [I])
{
I ++;
}
the else IF (ZH [I] == '\ n-' '&& ZH [I] =!') // account verification is complete, ready to verify the password.
{
The while (! (Mm [J] = fgetc (P)) = the EOF)
{
IF (mm [J] == k.mm [J])
{
J ++;
Continue;
}
the else IF (mm [J] == ' '&& mm [i] =! ' \ n ') // successful authentication password
{
the printf ( "successful login !!");
return 0;
}
the else // password authentication fails
{printf ( "% c", mm [i] );
fseek (P, -1,1);
GOTO lose;
}
}
}
an account verification at else //
{
I = 0;
HH the while ((= fgetc (P))! = & the EOF
IF (HH == '' HH = &&! '\ n-')
{
Q ++;
}
}
Q = 0;
}
}
fclose (P);
lose: the printf ( "account number or password, select: \ n 1. Re enter \ n 2. Register \ n 0. exit system \ n "); // verification failed
Scanf ("% D ", & D);
Switch (D)
{
Case. 1:
return. 1;
BREAK;
Case 2:
return 2;
BREAK;
Case 0:
Exit (. 1);
BREAK;
}
return 0;
}
int zhuce ()
{
the FILE * P;
SJ K;
the printf ( "Please enter the account password (* do not enter a space *) \ n-account:") ; // enter your registration information
scanf ( "% S", k.zh);
printf ( "password:");
Scanf ( "% S", k.mm);
P = the fopen ( "D: \\ shuju.txt", "A"); // open file
if (p == 0) // open successful verification documents
{
the printf ( "Source file text error \ n-");
Exit (. 1);
}
fputs (k.zh, P); // write the file
of fputc ( '', P);
fputs (k.mm, P);
of fputc ( '', P);
of fputc ( '\ n-', P);
fclose (P); // close file
printf ( "registered successfully !!");
return 0;
}
int main ()
{
MENU (); / / menu display
int C;
int A;
Scanf ( "% D", & C);
Switch (C) selected //
{
Case. 1:
the begin: the printf ( "Please enter the account password \ n account:");// Log
scanf ( "% s", k.zh );
printf ( "Password:");
Scanf ( "% S", k.mm);
A = denglu ();
IF (A ==. 1) // Error code
{
GOTO the begin;
}
the else IF (A == 2) // Register
{
zhuce ();
printf ( "Please login \ the n-");
GOTO the begin;
}
BREAK;
Case 2:
zhuce (); // Register
printf ( "Please login \ the n-");
GOTO the begin;
BREAK;
Case 0: exit (1); // exit system
BREAK;
}
return 0;
}
After the actual operation found that registration functions correctly, no problem. But I can not tell when the account password are the same characters, such as account number: 2222222, Password: 2222222
Enter the account number wrong occasionally garbled when landing.
But after the wrong password when logging will be garbled.
I do not know how to solve. (Goto suspected problems)