Course Design-Address Book Management System

Source: Internet
Author: User

After sorting out the file, I found the course design report last year and saved the code. I thought it was not good to write the code after six months, it indicates that there has been a little progress; this shows that there should be a little progress ~

# Include <stdio. h> # include <stdlib. h> # include <string. h> # include <conio. h>/* screen operation function library */# define header1 "| ************************ Address Book ** * ******************* | \ n "# define header2" | No. | Name | phone number | Address | \ N "# define header3" | --------- | ----------------- | ------------------------- | ----------------------- | \ n "# define end" | terminate | \ n "int input (); in T show (); void DELE (); void save (); int change (); int Cx (); int find1 (); int find2 (); int find3 (); void quit (); // struct telebook {int num; char name [20]; char phonenum [20]; char ADDR [30] ;}; void printheader ()/* format the output menu header */{printf (header1); printf (header2 ); printf (header3 );} //////////////////////////////////////// // communication information input /////////////////////////////////// //// // int input (struct Telebook temp []) {char sign, X [20]; int I = 0; file * FP;/* define file pointer */system ("CLS "); if (FP = fopen ("telebook.txt", "AB +") = NULL)/* If the reading and writing of the Two-Step file telebook.txt fails, the error message */{printf ("An error occurred while opening the file! "); Exit (0);} while (sign! = 'N' & sign! = 'N') {printf ("\ t No.:"); scanf ("\ t % d", & temp [I]. num); printf ("\ t name:"); scanf ("\ t % s", temp [I]. name); printf ("\ t phone number:"); scanf ("\ t % s", temp [I]. phonenum); printf ("\ t Mailing address:"); scanf ("\ t % s", temp [I]. ADDR); gets (x); printf ("\ n \ t continue to join ?? (Y/n) "); scanf (" \ t % C ", & sign); I ++;} fwrite (& temp [I], sizeof (struct telebook ), 1, FP); fclose (FP); System ("CLS"); Return 0 ;} //////////////////////////////////////// /// display the communication information ////////////////////////////////// //// // int show (struct telebook temp []) {int I; printheader (); for (I = 0; I <100; I ++) {If (temp [I]. num = '\ 0') break; printf ("%-10D %-20 S %-20 S %-20s \ n", temp [I]. num, temp [I]. name, temp [I]. phonenum, Temp [I]. ADDR);} printf ("--------------------------------------------------- \ n"); System ("pause"); System ("CLS"); Return 0 ;} //////////////////////////////////////// /delete communication information //////////////////////////////////// /////////// void DELE (struct telebook temp []) {char s [20]; int I = 0, J; show (temp); printf ("\ t enter the name in the record to be deleted :"); scanf ("% s", S); for (I = 0; I <100; I ++) {If (strcmp (temp [I]. name, S) = 0) {for (j = I; j <20; j ++) {T EMP [J] = temp [J + 1];} printf ("\ t has been deleted successfully! \ N "); getch (); System (" CLS "); Return ;}} printf (" \ t address book does not contain this person! \ N "); getch (); System (" CLS ");} /// // Communication information Storage ////////////////////////////////////// //////// void save (struct telebook temp []) {int I; file * FP; If (FP = fopen ("telebook.txt", "W") = NULL) {printf ("cannot open this file \ n"); exit (0) ;}for (I = 0; strlen (temp [I]. name )! = 0; I ++) fprintf (FP, "% d % S % s \ n", temp [I]. num, temp [I]. name, temp [I]. phonenum, temp [I]. ADDR); fclose (FP );} //////////////////////////////////////// /// communication information change ////////////////////////////////// //// // int change (struct telebook temp []) {char s [20]; int I = 0; show (temp); printf ("\ t enter the name of the record to be modified :"); scanf ("% s", S); for (I = 0; I <100; I ++) {If (strcmp (temp [I]. name, S) = 0) {printf ("\ t No.:"); scanf ("\ t % d", & temp [I]. num); printf ("\ t name:"); scanf ("\ t % s", temp [I]. name); printf ("\ t phone number:"); scanf ("\ t % s", temp [I]. phonenum); printf ("\ t Mailing address:"); scanf ("\ t % s", temp [I]. ADDR); printf ("\ t modified successfully! "); Getch (); System (" CLS "); Return 0 ;}{ printf (" \ t address book does not contain this person! \ N "); return;} getch (); System (" CLS ");} /// // communication information query /////////////////////////////////////// //// int Cx (struct telebook temp []) {int N, flag = 1; printf ("how do you want to search? \ N "); printf (" \ T1. No. \ t \ T2. name \ t \ T3. phone number \ T4. return \ n "); scanf (" % d ", & N); do {If (n = 1) {find1 (temp); return;} If (n = 2) {find2 (temp); return ;} if (n = 3) {find3 (temp); return;} If (n = 4) {system ("CLS"); return;} else {flag = 0; printf ("incorrect input, please input again:"); scanf ("% d", & N) ;}} while (flag = 0); Return 0 ;} //////////////////////////////////////// //// query by serial number ///////////////////////////////// /// // int find1 (Struct telebook temp []) {int I = 0, S = 0; printf ("\ t enter the number you want to query:"); scanf ("% d ", & S); for (I = 0; I <100; I ++) {If (temp [I]. num = s) {printheader (); printf ("%-10D %-20 S %-20 S %-20s \ n", temp [I]. num, temp [I]. name, temp [I]. phonenum, temp [I]. ADDR); getch (); System ("CLS"); Return 0 ;}} printf ("\ t address book does not contain this person! \ N "); getch (); System (" CLS "); return 1 ;} //////////////////////////////////////// /query by name //////////////////////////////////// //// // int find2 (struct telebook temp []) {char s [20]; int I = 0; printf ("\ t enter the name you want to query:"); scanf ("% s", S ); for (I = 0; I <100; I ++) {If (strcmp (temp [I]. name, S) = 0) {printheader (); printf ("%-10D %-20 S %-20 S %-20s \ n", temp [I]. num, temp [I]. name, temp [I]. phonenum, temp [I]. ADDR); getch (); s Ystem ("CLS"); Return 0 ;}} printf ("\ t address book does not contain this person! \ N "); getch (); System (" CLS "); return 1 ;} //////////////////////////////////////// // query by phone number ////////////////////////////////// //// // int find3 (struct telebook temp []) {char s [20]; int I = 0; printf ("\ t enter the phone number you want to query:"); scanf ("% s", S ); for (I = 0; I <100; I ++) {If (strcmp (temp [I]. phonenum, S) = 0) {printheader (); printf ("%-10D %-20 S %-20 S %-20s \ n", temp [I]. num, temp [I]. name, temp [I]. phonenum, temp [I]. ADDR); getch (); System ("CLS"); Return 0 ;}} printf ("\ t address book does not contain this person! \ N "); getch (); System (" CLS "); return 1 ;} /// // void quit () {printf ("\ n"); printf ("\ n"); printf ("\ t★★★★★★★★★★★★★★★★★★★★★\ N "); printf (" \ t★★★★★★★Thank you for your use.★★★★★★★★\ N "); printf (" \ t★★★★★★★Welcome to use again★★★★★★★★\ N "); printf (" \ t★★★★★★★★★Thank you.★★★★★★★★★★\ N "); exit (0); getch (); System (" CLS ");} /// // Main Function //////////////////////////////////////// //// // int main () {struct telebook mess [100]; char xx; System ("color 2e");/* Change console color */while (1) {printf ("\ t★☆★☆★[Welcome to the address book management system]★☆★☆★\ N "); printf ("\ t ************** * ***** \ n "); printf ("\ t ┌ ── ─ ┐ \ n "); printf ("\ t ● A. Communication Information Input \ n"); printf ("\ t ● B. Communication Information Display \ n "); printf ("\ t ● C. Save communication information \ n"); printf ("\ t ● D. Delete communication information \ n "); printf ("\ t ● E, communication information change \ n"); printf ("\ t ● F, Communication Information Query \ n "); printf ("\ t ◆ I, query by ID \ n"); printf ("\ t ◆ II, query by name \ n "); printf ("\ t ◆ III. query by phone number \ n"); printf ("\ t ● g, exit system \ n "); printf ("\ t └ ── ─ ┘ \ n "); printf ("\ t ********************************* * ******** \ n "); printf ("Enter your choice \ n"); scanf ("% C", & XX); getchar (); System ("CLS"); Switch (XX) {Case 'A': input (MESS); break; Case 'B': Show (MESS); break; Case 'C': Save (MESS); break; case 'D': DELE (MESS); break; Case 'E': Change (MESS); break; Case 'F': Cx (MESS); break; case 'G': Quit (); break; default: Return 0;} getchar ();} return 0 ;}
It is a little simple, just to compare your learning status, and compare it with the previous, to see if there are any progress ~ Use your past as a mirror to inspire yourself !!!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.