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;
}
}
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C 언어 구현 천둥 제거 게임 상세 정보먼저 작은 메뉴를 표시하고 게임을 할지 여부를 선택하십시오.사용자가 종료를 선택하면 프로그램 실행이 끝나고, 사용자가 게임을 선택하면 지뢰 제거 위치 좌표를 입력하라는 메시지가 표시됩니다.사용자가 입력한 좌표가 바둑...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.