#include
#include
#include
#include
//user information
Typedef struct tagPerson
{
Char szUsername [20].
Char szPassword [7].
Char szAccoutNumber [20].
Float fMoney;
} Person;
Typedef struct tagNode
{
Person per;//data domain
Struct tagNode * pNext;//pointer field
} the Node;
Node * g_pHead=NULL;//head node
//accounts
Int CreateAccout ();
Int main ()
{
System (color 2 "f");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ n \ t \ \ t t * * ");
Printf (" \ t \ \ t t bank ATM * * empire \ n ");
Printf (" \ n \ t \ \ t t * * ");
Printf (" \ t \ \ t t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ n \ t \ \ t t * * ");
Printf (" \ t \ \ t t * 1. Open an account * \ n ");
Printf (" \ t \ \ t t * 2. Login * \ n ");
Printf (" \ t \ \ t t * 3. The front desk information center * \ n ");
Printf (" \ t \ \ t t * 4. Please select your need * \ n ");
Printf (" \ n \ t \ \ t t * * ");
Printf (" \ t \ \ t t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Char ch=getch ();
The switch (ch)
{
Case '1' : CreateAccout ();
break;
Case '2' :
break;
Case '3' :
break;
Case '4' :
break;
}
while(1);
return 0;
}
Int CreateAccout ()
{
Printf (" please input your name \ n ");
Char szUsername [20].
The scanf (" % s ", szUsername);
Printf (" please set your bank card password \ n ");
Char szPassword [7].
The scanf (" % s ", szPassword);
Printf (" please set your bank card password again \ n ");
Char szRePassword [7].
The scanf (" % s ", szRePassword);
If (0!=STRCMP (szPassword szRePassword))
{
Printf (" input password twice. \ n ");
return 0;
}
//generate a bank accountChar szAccoutNum [20].
Srand ((unsigned int) time (NULL));
Sprintf (szAccoutNum, "% d % d % d % d % d % d", (rand () % 9000) + 1000, (9000) the rand () % + 1000, (9000) the rand () % + 1000, (9000) the rand () % + 1000, (9000) the rand () % + 1000, rand () % 10, rand () % 10);//format a string
Node * p=g_pHead;
While (g_pHead!=NULL& & P - & gt; PNext!=NULL)
{
P=p - & gt; PNext;
}
//generic pointer to void *
Node * pNewNode=(*) malloc (sizeof (Node));
The STRCMP (pNewNode - & gt; Per the szUsername szUsername);
The STRCMP (pNewNode - & gt; Per the szPassword szPassword);
The STRCMP (pNewNode - & gt; Per szAccoutNumber, szAccoutNum);
PNewNode - & gt; Per. FMoney=0.0 f;
//added to the end node
If (g_pHead==NULL)
{
G_pHead=pNewNode;
}
The else
{
P - & gt; PNext=pNewNode;
}
Printf (" your account information is as follows: \ n ");
Printf (" \ n \ t name: % s ", pNewNode - & gt; Per. SzUsername);
Printf (" \ n \ t card number: % s ", pNewNode - & gt; Per. SzAccoutNumber);
Printf (" \ t balance: % 0.2 f \ n ", pNewNode - & gt; Per. FMoney);
Printf (" congratulations, account application is successful. Please login \ n ");
return 1;
}
Why has the code behind.
CodePudding user response:
You directly use thePrintf (" \ n \ t name: % s ", szUsername);
Give it a try, if the output is normal, that Node * pNewNode=(*) malloc (sizeof (Node)); Application of memory not clean,
After using memset will reset the region's give it a try,
Memset (pNewNode, 0, sizeof (Node));