Current location - Quotes Website - Signature design - Qiu Yi C Language Address Book Management System
Qiu Yi C Language Address Book Management System
Please contact/4381929 _ d.html.

# include & ltstdio.h & gt

# include & ltstring.h & gt

# include & ltstdlib.h & gt

#define LEN sizeof (structural address book)

# Define Max 100

void InitDialBook(void);

void user interface(void); /* Menu function */

Invalid load (void);

void Add(void);

Void Find (invalid);

Void Modify (invalid);

Void Delete (void);

Void ShowAll (invalid);

Void Save (void);

Structural address book {

Int record;

char name[ 15];

char sex[4];

Char age [4];

char addr[20];

Charging phone [15];

char QQ[ 15];

char Meg[40]; /* Personal signature */

struct addbook * link

};

FILE * fp

struct addbook *p,*p 1,*head,*s,* t;

Master ()

{

Int mark;

Int selection;

if((fp = fopen("zzxx.txt "," Rb ")= = NULL)

{ clr SCR();

Printf ("\ n \ n \ t \ tThe file does not exist! \ n ");

if((fp = fopen("zzxx.txt "," WB ")= = NULL)

{

Printf ("File open error! \ n ");

getch();

Exit (0);

}

}

if(fgetc(fp)==- 1)

{

Printf(" \ n \ t \ t tThere is no information in the address book. Now, you must add information. \ n ");

InitDialBook();

Printf(" \ n \ t \ t \ t tAdded successfully! \ n ");

Printf ("\ n \ t \ tIf you want to add more people's information, please reopen the program \ n");

getch();

Exit (0);

}

Rewind (FP); /* Rebuild file pointer */

load();

fclose(FP);

/* printf ("\ nThis is the %d member in the file. \n ",p-& gt; Records); */

flag = 1;

While (sign)

{

user interface();

Printf ("Please enter your choice: (0-5):");

Scanf("%d ",& select);

getchar();

If (select & gt= 0 & amp& amp select & lt6)

{

Switch (selection)

{

Case 1:

add(); Break;

Case 2:

find(); Break;

Case 3:

ShowAll(); Break;

Case 4:

delete(); Break;

Case 5:

modify(); Break;

Case 0:

flag = 0;

clr SCR();

Printf ("\ n \ n \ n \ t \ tThank you for using this address book system! ! !" );

Printf ("\ n \ n \ t \ tIf you have any requirements or suggestions during use, please contact:");

Printf ("\ n \ n \ t \ tzzzx2001@126.com or QQ: 279252614");

getch();

Break;

}

}

Otherwise {

Printf ("Input error, please select again! \ n ");

}

}

fp = fopen("zzxx.txt "," WB ");

save();

fclose(FP); clr SCR();

Printf(" \ n \ n \ n \ t \ t tPress any key to exit! \ n ");

getch();

Returns 0;

}

Voidinitialbook (void)/* Initialize file function */

{

p->; Record =1;

Printf(" \ n \ n \ t \ t tPlease enter a name: ");

Get (p->; Name);

Printf(" \ n \ t \ t tPlease enter gender: ");

Get (p->; Sex);

Printf(" \ n \ t \ t tPlease enter age: ");

Get (p->; Age);

Printf(" \ n \ t \ t tPlease enter an address: ");

Get (p->; addr);

Printf(" \ n \ t \ t tPlease enter a phone number: ");

Get (p->; Telephone);

Printf(" \ n \ t \ t tPlease enter QQ number: ");

Get (p->; QQ);

Printf(" \ n \ t \ t tPlease enter a personalized signature: ");

Get (p->; Meg);

p->; link = NULL

head = p;

fwrite(p,LEN, 1,FP);

fclose(FP);

}

void user interface(void)/* menu */

{ clr SCR();

printf(" \ n \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");

Printf ("\ t \ t \ tWelcome to the address book management system");

printf(" \ n \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");

Printf ("\ n \ n \ t \ t * * * * Please select your operation * * * \ n ");

printf(" \ t \ t \ t++ ");

Printf ("\ t \ t \ t \ t |1Add Personal Information | \ n");

Printf ("\ t \ t | 2 Search information (including deleting \ modifying information) | \ n ");

Printf ("\ t \ t | 3 Show all information | \ n ");

Printf ("\ t \ t | 4 Delete information | \ n ");

Printf ("\ t \ t | 5 Modify information | \ n ");

Printf ("\ t \ t | 0Exit and save | \ n");

printf(" \ t \ t \ t++ \ n ");

Printf ("\ n \ n \ tAttention! ! The number entered (phone number or QQ) must be in English status, and Chinese status cannot be entered! ! \ n \ n ");

}

Void Load(void)/* read file */

{

fread(head,LEN, 1,FP);

P = head;

while(p->; Link! =NULL){

p 1 =(struct addbook *)malloc(LEN);

p 1 = p->; Link;

fread(p 1,LEN, 1,FP);

p = p-& gt; Link;

}

}

Voideadd (void)/* input function */

{

p 1 =(struct addbook *)malloc(LEN);

p 1->; record = p-& gt; Record+1; clr SCR();

printf(" \ n \ n \ t \ t \ t-\ n ");

Printf ("\ t \ t \ t \ t \ tPlease enter information \ n");

printf(" \ t \ t \ t-\ n ");

Printf(" \ n \ t \ t \ t tThis is a member of %d ",p-> Record+1);

Printf(" \ n \ t \ t \ t tPlease enter a name: ");

Get (p1->; Name);

Printf(" \ n \ t \ t \ t tPlease enter gender: ");

Get (p1->; Sex);

Printf(" \ n \ t \ t \ t tPlease enter age: ");

Get (p1->; Age);

Printf(" \ n \ t \ t \ t tPlease enter an address: ");

Get (p1->; addr);

Printf(" \ n \ t \ t \ t tPlease enter a phone number: ");

Get (p1->; Telephone);

Printf(" \ n \ t \ t \ t tPlease enter QQ number: ");

Get (p1->; QQ);

Printf(" \ n \ t \ t \ t tPlease enter a personalized signature: ");

Get (p1->; Meg);

p 1->; link = NULL

p->; link = p 1;

p = p 1;

}

Void ShowAll(void)/* Show all functions */

{

S = head;

clr SCR();

printf(" \ n \ n ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ n ");

Printf(" \ t t tSerial number name gender age address telephone QQ number personalized signature ");

printf(" \ n ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ n ");

Do {

printf(" \ t %-6d %- 10s %-8s %-7s %- 10s %- 10s %-s %-s \ n ",s-& gt; Record, s-> Name, s-> Sex,

s-& gt; Age, s-> addr,s-& gt; Telephone, s-> qq,s-& gt; Meg);

s = s-& gt; Link;

}while(s! = NULL);

Printf(" \ n \ n \ n \ t \ t tPress any key to exit! " );

getch();

Return;

}

Void Find(void)/* Find function */

{

char c;

struct addbook who

S = head;

clr SCR();

Printf(" \ n \ t \ t tPlease enter the name of the person you are looking for: ");

Get (who.name);

while((s-& gt; Link! = NULL)& amp; & amp(strcmp(s-& gt; Name, who.name))

{

s = s-& gt; Link;

}

if((s-& gt; link = = NULL)& amp; & amp(strcmp(s-& gt; Name, who.name))

{

Printf("% s ") does not exist! \n ",who . name);

Printf ("Please check the name before searching. \ n ");

getch();

Return;

}

clr SCR();

Printf("\n\t\t\t\ The information to be searched is as follows: \ n ");

printf(" \ n * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");

Printf ("\ tSerial number name gender age address telephone QQ number personalized signature");

printf(" \ n * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");

printf(" \ t %-6d %- 10s %-8s %-7s %-8s %- 10s %-s %-s \ n ",s-& gt; Record, s-> Name, s-> Sex, s-> Age, s-> Age,

s-& gt; addr,s-& gt; Telephone, s-> qq,s-& gt; Meg);

printf(" \ n \ t \ t delete(d)\ Modify(m)\ Browse(s)\ n ");

Printf ("\ n \ tPlease enter your choice (d/m/s):");

scanf("%c ",& ampc);

Switch (c)

{

Case "d":

Case "d": delete (); Break;

Case "m":

Case "m": modify (); Break;

}

}

Invalid modification (invalid)

{ getchar();

Printf(" \ n \ t \ t tPlease enter a new name: ");

Get (s->; Name);

Printf(" \ n \ t \ t tPlease enter a new gender: ");

Get (s->; Sex);

Printf(" \ n \ t \ t tPlease enter a new age: ");

Get (s->; Age);

Printf(" \ n \ t \ t tPlease enter a new address: ");

Get (s->; addr);

Printf(" \ n \ t \ t tPlease enter a new phone number: ");

Get (s->; Telephone);

Printf(" \ n \ t \ t tPlease enter a new QQ number: ");

Get (s->; QQ);

Printf(" \ n \ t \ t tPlease enter a new personalized signature: ");

Get (s->; Meg);

Printf(" \ n \ t \ t tModified successfully! \ n ");

getch();

}

Void Delete(void)/* Delete function */

{

int find _ prev

int find _ record

char del

char del _ member _ name[ 15];

struct addbook * p _ del _ prev

strcpy(del_member_name,s-& gt; Name);

getchar();

Printf ("Are you sure you want to delete %s (Y/N)?" ,del _ member _ name);

scanf("%c ",& ampdel);

if(del=='n'||del=='N ')

{

Return;

}

find _ prev = s-& gt; Record-1;

find _ record = 1;

p _ del _ prev = head

while((p _ del _ prev-& gt; Link! = NULL)& amp; & amp(find _ record & ltfind_prev))

{

p _ del _ prev = p _ del _ prev-& gt; Link;

find _ record++;

}

/* If the first member is deleted */

if(s-& gt; Record == 1)

{

if(s-& gt; Link! = empty)

{

head = head-& gt; Link;

S = head;

while(s! = empty)

{

s-& gt; record = s-& gt; Record-1;

s = s-& gt; Link;

}

printf("%d,%s ",p-& gt; Record, p-> Name);

}

else if(s-& gt; Link==NULL){ /* If the first member is the last */

p = NULL

head = p;

if(remove("zzxx.txt")==0){

Printf ("You have deleted the last member, and the address book has been emptied! \ n ");

Printf ("So, you must re-create the address book! \ n ");

Printf ("Reopen program creation. \ n ");

}

Printf(" \ n \ n \ t \ t tPress any key to exit. \ n ");

getch();

Exit (0);

}

}

/* If the last member is deleted */

else if(s-& gt; record = = p-& gt; Record) {

p _ del _ prev-& gt; link = NULL

s-& gt; link = NULL

p = p _ del _ prev

}

Otherwise {

p _ del _ prev-& gt; link = s-& gt; Link;

s-& gt; link = NULL

while(p _ del _ prev->; Link! = empty)

{

p _ del _ prev = p _ del _ prev-& gt; Link;

p _ del _ prev-& gt; record = p _ del _ prev-& gt; Record-1;

}

printf("%d\n%d\n ",p-& gt; Record, p-> Link);

}

Printf ("member \"%s\" has been deleted. \n ",del _ member _ name);

getch();

}

Void Save(void)/* Save file */

{

S = head;

Do {

fwrite(s,LEN, 1,FP);

s = s-& gt; Link;

}while(s! = NULL);

}

Label: c language