#include
#include
#include
//set a menu for program
//1. Increase the data
//2. Delete the data
//3. To view a data
//4. Look at all the data
//5. To modify a data
Exit//6.
//create a structure, members of the site, account, password
//in creating a global structure array
//AddData DeleteData CheckData ViewAllData ModData Exit SaveData InitData
# define increase data 1
# define delete data 2
3 # define view a data
# define data to see all 4
# define data to modify a 5
# define exit the program 6
Void AddData ();
Void ViewAllData ();
Void the Exit ();
Void DeleteData ();
Void CheckData ();
Void ModData ();
Void SaveData ();
Void InitData ();
Typedef struct _PWDINFO
{
Char szWedsite [20].
Char szUseName [20].
Char szPassword [20].
} the INFO, * PINFO;
The INFO g_info [100]={};
Int g_count=0;
Int g_nFind=1;
Void AddData ()
{
Printf (" please enter the site to store: \ n ");
Scanf_s (" % s ", g_info [g_count] szWedsite, 20).
Printf (" please enter to store account: \ n ");
Scanf_s (" % s ", g_info [g_count] szUseName, 20).
Printf (" please enter a password to be stored: \ n ");
Scanf_s (" % s ", g_info [g_count] szPassword, 20).
G_count + +;
SaveData ();
system("pause");
system("cls");
}
Void ViewAllData ()
{
for(int i=0; i
Printf (" view website: % s \ n ", g_info [I] szWedsite);
Printf (" view account: % s \ n ", g_info [I] szUseName);
Printf (" view password: % s \ n ", g_info [I] szPassword);
}
system("pause");
system("cls");
}
Void the Exit ()
{
Printf (" exit success ");
G_nFind=0;
}
Void DeleteData ()
{
Char cCh [20]={};
Int nFind=0;
Int I=0;
Printf (" please enter the need to delete the site: ");
Scanf_s (" % s ", & amp; The cCh, 20);
For (; I & lt; G_count; I++)
{
If (STRCMP (cCh, g_info [I] szWedsite)==0)
{
NFind=1;
break;
}
}
If (nFind==1)
{
For (int nIndex=I; NIndex & lt; G_count; NIndex++)
{
Strcpy_s (g_info [I] szWedsite, 20, g_info [I + 1] szWedsite);
Strcpy_s (g_info [I] szUseName, 20, g_info [I + 1] szUseName);
Strcpy_s (g_info [I] szPassword, 20, g_info [I + 1] szPassword);
}
G_count -;
SaveData ();
}
The else
{
Printf (" no storage sites ");
}
system("pause");
system("cls");
}
Void CheckData ()
{
Char cCh [20]={};
Int I=0;
Printf (" please enter the need to look at the site: ");
Scanf_s (" % s ", & amp; The cCh, 20);
If (g_count==0)
{
Printf (" account does not exist \ n ");
}
For (; I & lt; G_count; I++)
{
If (STRCMP (cCh, g_info [I] szWedsite)==0)
{
Printf (" to view a data site: % s \ n ", g_info [I] szWedsite);
Printf (" to view a data account: % s \ n ", g_info [I] szUseName);
Printf (" to view a data password: % s \ n ", g_info [I] szPassword);
}
}
system("pause");
system("cls");
}
Void ModData ()
{
Char cCh [20]={};
Int I=0;
Int nFind=0;
Printf (" please enter the need to modify the site: ");
Scanf_s (" % s ", & amp; The cCh, 20);
If (g_count==0)
{
Printf (" account does not exist \ n ");
}
For (; I & lt; G_count; I++)
{
If (STRCMP (cCh, g_info [I] szWedsite)==0)
{
NFind=1;
break;
}
}
If (nFind==1)
{
Printf (" please enter account: \ n ");
Scanf_s (" % s ", g_info [I] szUseName, 20).
Printf (" please enter the password: \ n ");
Scanf_s (" % s ", g_info [I] szPassword, 20).
SaveData ();
}
The else
{
Printf (" account does not exist \ n ");
}
system("pause");
system("cls");
}
Void SaveData ()
{
The FILE * pFile=NULL;
Fopen_s (& amp; PFile, "123. TXT", "wb +");
If (pFile!=0)
{
Fwrite (& amp; G_count, 4, 1, pFile);
Fwrite (& amp; G_info, sizeof (INFO), g_count, pFile);
}
The fclose (pFile);
}
Void InitData ()
{
The FILE * pFile=NULL;
Errno_t Errno=fopen_s (& amp; PFile, "123. TXT", "rb +");
If (Errno!=0 | | pFile==0)
{
G_count=0;
}
The else
{
Fread (& amp; G_count, 4, 1, pFile);
Fread (& amp; G_info, sizeof (INFO), g_count, pFile);
The fclose (pFile);
}
}
Int main ()
{
Int nSelect=1;
InitData ();
While (g_nFind)
{
Printf (" \ n \ n1. Added data ");
Printf (" 2. Delete the data \ n ");
Printf (" 3. To view a data \ n ");
Printf (" 4. To see all data \ n ");
Printf (" 5. To modify a data \ n ");
Printf (" 6. Quit \ n ");
Printf (" please select a function: ");
Scanf_s (" % d ", & amp; NSelect);
If (nSelect>=1 & amp; & NSelect
=6){
The switch (nSelect)
{
Case to increase data: {AddData (); } break;
Case delete data: {DeleteData (); } break;
Case check a data: {CheckData (); } break;
Case to see all the data: {ViewAllData (); } break;
Case modify a data: {ModData (); } break;
Exit case: {the Exit (); } break;
Default: {} break;
}
}
The else
{
Printf (" input errors, please choose again ");
}
}
return 0;
} [align=center]