C 언어 실현 간단 한 전자 주소록

10981 단어 C 언어통신 록
본 논문 의 사례 는 C 언어 가 전자 주소록 을 실현 하 는 구체 적 인 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.
이 주소록 을 통 해 친구 ID,이름(영어),손 을 입력 할 수 있 는 전자 주소록 을 만 듭 니 다.
전화번호,집 주소,회사 전화번호.
원리:5 개의 모듈 로 나 누 어 모듈 기능 을 헤더 파일 에 기록 합 니 다.주 함수 부분 코드:
함수 부분 을 표시 합 니 다.Markdown 에서 일치 하지 않 습 니 다.뜻 은 이 렇 습 니 다.아 쉬 운 대로==  


/*******************************************************************
  :         ,           ID 、  (  )、 
   ,    ,    。
  :
    :        ,A)       B)      。(    
   ) C)     D)    
 A)    INSERT   ,         。           
 B)    DISPLAY   ,        
 C)    SEARCH   ,               。     
       。     ,        
 D)    DELETE   ,               ,     
       ,    ,         ,       ID   
         。
**********************************************************************/
#include "head.h"

int main ()
{
 int Function;
 int i = 0;
 char Name[N];
 int cho;

 PNode head_node = (PNode) malloc(sizeof(Node)/sizeof(char));
 if (NULL == head_node)
 {
  return MALLOC_ERROR;
 }
 head_node->next = NULL;

 while (1)
 {
  Interface_Display ();
  scanf ("%d", &Function);

  switch (Function)    //     
  {
   case 1:      //     
   {
    Function = 0;
    Add_Friend (head_node, i++);
    int j;

    printf ("\t    
"); printf ("\t "); fflush (stdout); // , for (j = 0; j < 3; j++) { sleep (1); // Linux sleep, printf ("."); fflush (stdout); // , } printf ("
"); printf ("\t !
"); printf ("\t 1:"); scanf ("%d", &cho); if (1 == cho) { break; } else { printf ("\t ! ! :"); scanf ("%d", &cho); break; } break; } case 2: // { system ("clear"); printf ("\t********* ********
"); printf ("
"); Friend_Information (head_node); Function = 0; printf ("\t 1:"); scanf ("%d", &cho); if (1 == cho) { break; } else { printf ("\t ! ! :"); scanf ("%d", &cho); break; } break; } case 3: // { system ("clear"); printf ("\t************* *************
"); printf ("\t :"); scanf ("%s", Name); printf ("
"); int j; printf ("\t
"); printf ("\t "); fflush (stdout); // , for (j = 0; j < 3; j++) { sleep (1); // Linux sleep, printf ("."); fflush (stdout); // , } printf ("
"); Search_Friend (head_node, Name); printf ("\t 1:"); scanf ("%d", &cho); if (1 == cho) { break; } else { printf ("\t ! ! :"); scanf ("%d", &cho); break; } break; } case 4: // { system ("clear"); printf ("\t************* *************
"); printf ("\t :"); scanf ("%s", Name); printf ("
"); Delete_Friend (head_node, Name); printf ("\t 1:"); scanf ("%d", &cho); if (1 == cho) { break; } else { printf ("\t ! ! :"); scanf ("%d", &cho); break; } break; } case 5: // { Function = 0; system ("clear"); exit (0); } default: // { Function = 0; printf ("\t ! ! :"); scanf ("%d", &Function); break; } } } return 0; }
head.h 부분:

#ifndef HEAD_H_
#define HEAD_H_

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>    // sleep     

#define uint unsigned int
#define OK   0
#define ERROR   -1
#define MALLOC_ERROR -2
#define N    20 

typedef int ElementType;
typedef struct node
{
 ElementType ID;    // ID 
 char Name [N];    //   
 char Mobile_Phone [N];  //     
 char Home_Address [N];  //     
 char Company_Tell [N];  //     
 struct node* next;   //     
}Node;
typedef Node* PNode;   //         

//      
int Interface_Display ();

//       (   )
int Add_Friend (PNode head, ElementType num);

//        
int Friend_Information (PNode head);

//    
int Search_Friend (PNode head, char* Name);

//    
void Delete_Friend (PNode head, char* Name);

#endif
head.c 의 코드:

#include "head.h"

//      
int Interface_Display ()
{
 system ("clear");
 printf ("\t************************************** 
"); printf ("\t~ ~
"); printf ("\t~ ~
"); printf ("\t~ 1 >>>>>>>> ~
"); printf ("\t~ 2 >>>>>>>> ~
"); printf ("\t~ 3 >>>>>>>> ~
"); printf ("\t~ 4 >>>>>>>> ~
"); printf ("\t~ 5 >>>>>>>> ~
"); printf ("\t~ ~
"); printf ("\t~ ~
"); printf ("\t~ :believe ~
"); printf ("\t~*************************************~
"); printf ("
"); printf ("
"); printf ("\t :"); } // ( ) int Add_Friend (PNode head, ElementType num) { if (NULL == head) { return ERROR; } // PNode p = (PNode) malloc(sizeof(Node)/sizeof(char)); if (NULL == p) { return MALLOC_ERROR; } // system("clear"); printf ("\t************* ***************
"); p->ID = num; printf ("\t ID :%d
", p->ID); printf ("
"); printf ("\t :"); scanf ("%s", p->Name); printf ("
"); printf ("\t :"); scanf ("%s", p->Mobile_Phone); printf ("
"); printf ("\t :"); scanf ("%s", p->Home_Address); printf ("
"); printf ("\t :"); scanf ("%s", p->Company_Tell); printf ("
"); p->next = NULL; // PNode Ptmp; // Ptmp Ptmp = head; while (Ptmp->next) { Ptmp = Ptmp->next; } Ptmp->next = p; return OK; } // int Friend_Information (PNode head) { if (NULL == head) { return ERROR; } PNode p = head->next; printf ("\tID\t \t\t \t\t \t\t\t
"); while (p) { printf ("\t%d\t%s\t\t%s\t\t%s\t\t\t%s
", p->ID, p->Name, p->Mobile_Phone, p->Home_Address, p->Company_Tell); p = p->next; } putchar('
'); return OK; } // int Search_Friend (PNode head, char* Name) // { PNode p = head; PNode q = NULL; if ((NULL != p) && NULL != (p->next)) { while (p->next) { q = p->next; if ((NULL != q) && 0 == (strcmp(q->Name, Name))) { printf ("\t :
\tID:%d
\t : %s
\t : %s
\t :%s
\t : %s
", q->ID, q->Name, q->Mobile_Phone, q->Home_Address, q->Company_Tell); } else { printf ("\t , !
"); } p = p->next; } } /* if (NULL == head) { return ERROR; } PNode p; int flag = 1; for (p = head->next; p != NULL; p = p->next) { if (0 == strcmp(p->Name, Name)) { flag = 0; printf ("\t :
\tID: %d
\t : %s
\t : %s
\t : %s
\t : %s
", p->ID, p->Name, p->Mobile_Phone, p->Home_Address, p->Company_Tell); } } fi (flag) { printf ("\t , !
"); } putchar('
'); */ return OK; } // void Delete_Friend (PNode head, char* Name) { PNode p = head; PNode q = NULL; while (NULL != p && NULL != (p->next)) { q = p->next; if (NULL != q && 0 == strcmp(q->Name, Name)) { p->next = q->next; free(q); int j; printf ("\t
"); printf ("\t "); fflush (stdout); // , for (j = 0; j < 3; j++) { sleep (1); //linux sleep, printf ("."); fflush(stdout); // , } printf ("
"); printf ("\t !
"); } else if (NULL == q->next && 0 != strcmp(q->Name, Name)) { printf ("\t !
"); } p = p->next; } }
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기