Skip to main content

[C언어] 주소록 (더블링크드리스트, 파일 입출력, 입력/검색/수정/삭제) P.P.B.P Ver2.4 소스

/********************************************************
*                                                      *
*   프로그램명 : Personal Phone Book Program Ver2.4    *
*                                                      *
*   작  성  자 : Romanric Programmer Teddy    *
*                blog – t-space.tistory.com            *
*                                                      *
*   기      능 : 입력, 검색, 수정, 삭제가 가능하고     *
*                파일로 저장이 되는 전화번호부         *
*                                                      *
*   최초작성일 : 2008년  5월  7일 Ver0.1               *
*                – 메모리에 입력,검색,삭제 구현        *
*                                                      *
*   2차 수정일 : 2008년  5월 28일 Ver1.0               *
*                – 링크드리스트 이용 입력, 출력 구현   *
*                                                      *
*   3차 수정일 : 2008년  5월 29일 Ver1.1               *
*                – 입력 예외처리, 인트로, 종료 추가    *
*                                                      *
*   4차 수정일 : 2008년  6월  4일 Ver2.0               *
*                – 파일 입출력 구현                    *
*                                                      *
*   5차 수정일 : 2008년  6월  7일 Ver2.1               *
*                – 파일 입출력 보강                    *
*                                                      *
*   6차 수정일 : 2008년  6월  8일 Ver2.2               *
*                – 이름, 전화번호로 검색 구현          *
*                                                      *
*   7차 수정일 : 2008년  6월 10일 Ver2.3                *
*                  – 수정 구현                            *
*                                                      *
*   8차 수정일 : 2008년  6월 11일 Ver2.4                *
*                  – 더블 링크드리스트, 삭제 구현        *
*                                                      *
********************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define NAME_LEN 15   /* 이름 저장 공간 */
#define PHONE_LEN 15  /* 번호 저장 공간 */
#define MAIL_LEN 30   /* 메일 저장 공간 */

/* 구조체 */
typedef struct LIST {
char name[NAME_LEN+1];
char phone[PHONE_LEN+1];
char mail[MAIL_LEN+1];
int group;
struct LIST *pPrev;
struct LIST *pNext;
} LIST;

void cleaning(float wait);                  /* 일정시간 대기후 화면 지우기    */
void Intro(void);                           /* 인트로 화면 출력                */
void PrintTitle(void);                      /* 제목 출력                    */
void MenuPrint(void);                       /* 메뉴 출력                    */
void ExitPrint(void);                       /* 종료 화면 출력                */
void AddList(LIST **dpHead, LIST **dpTail); /* 리스트 추가                    */
LIST * SearchList(LIST **dpHead);            /* 특정 리스트 검색                */
void ModifyDelete(LIST **dpHead);            /* 수정 / 삭제 함수                */
void SortList(LIST **dpHead);                /* 이름순으로 정렬                */
void PrintList(LIST **dpHead);              /* 리스트 출력                    */
void Outtro(void);                            /* 아웃트로 출력                */

int main(void)
{
LIST *pHead = NULL; /* 머리부분            */
LIST *pTail = NULL; /* 꼬리부분            */
LIST *pNew = NULL;  /* 추가부분            */
int choice;            /* 메뉴선택            */
char yesno;            /* yes or no 선택    */
FILE *fp;
int res;

Intro();
cleaning(2.0);

/* 파일 오픈 */
fp = fopen(”list.dat”, ”r”);
/* 파일이 없다면 새로운 파일을 생성 */
if(fp == NULL) {
while(fp == NULL) {
PrintTitle();
printf(”  !!! warning : \”list.dat\”파일이 없습니다. !!!\n\n”);
printf(”  새로 생성하시겠습니까(Y/N)? ”);
scanf(”%c”, &yesno);
fflush(stdin);
if(yesno == ’y’ || yesno == ’Y’) {
fp = fopen(”list.dat”, ”w+”);
if(fp == NULL) {
printf(”\n\n  !!! errer : 파일 생성에 실패하여 프로그램을 실행 할 수 없습니다. !!!\n”);
printf(”  !!! errer : 프로그램을 종료합니다.                               !!!\n”);
system(”pause”);
return 1;
}
printf(”\n\n  ** 파일 생성이 완료되었습니다. **\n”);
cleaning(1.0);
}
else if(yesno == ’n’ || yesno == ’N’) {
printf(”\n\n  !!! errer : 파일을 생성하지 않아 프로그램을 실행 할 수 없습니다. !!!\n”);
printf(”  !!! errer : 프로그램을 종료합니다.                               !!!\n”);
system(”pause”);
return 1;
}
else {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
}
}
}
/* 파일 내용 읽어들임 */
while(1) {
pNew = (LIST *) malloc(sizeof(LIST));
res = fscanf(fp, ”%s %s %s %d”, pNew->name, pNew->phone, pNew->mail, &pNew->group);
pNew->pNext = NULL;
pNew->pPrev = pTail;
if(res == EOF) break;
if(pTail != NULL) {
pTail->pNext = pNew;
pTail = pNew;
}
else {
pHead = pNew;
pHead->pPrev = NULL;
pTail = pHead;
}
}
fclose(fp);

while(1) {
PrintTitle();
MenuPrint();
scanf(”%d”, &choice);
fflush(stdin);
if( choice < 1 || 5 < choice ) {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}
cleaning(1.0);
switch(choice) {
case 1:
AddList(&pHead, &pTail);
cleaning(2.0);
break;

case 2:
SearchList(&pHead);
cleaning(2.0);
break;

case 3:
ModifyDelete(&pHead);
cleaning(2.0);
break;

case 4:
PrintList(&pHead);
system(”pause”);
cleaning(2.0);
break;

case 5:
while(1) {
ExitPrint();
scanf(”%c”, &yesno);
fflush(stdin);
if( yesno == ’y’ || yesno == ’Y’ ) {
/* 메모리 리스트를 파일에 저장 */
fp = fopen(”list.dat”, ”w”);
if(fp == NULL) {
printf(”\n\n  !!! errer : 파일에 저장이 실패하였습니다. !!!\n”);
system(”pause”);
return 1;
}
while(1) {
fprintf(fp, ”%s %s %s %d\n”, pHead->name, pHead->phone, pHead->mail, pHead->group);
pHead = pHead->pNext;
if(pHead == NULL) break;
}
fclose(fp);
Outtro();
exit(0);
}
else if( yesno == ’n’ || yesno == ’N’ ) {
printf(”\n\n  메인으로 돌아갑니다.\n”);
cleaning(1.0);
break;
}
else {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}
}
}
}
}

void cleaning(float wait)
{
clock_t m = ( (clock_t) wait * CLOCKS_PER_SEC );
clock_t goal;
goal = m + clock();
while( goal > clock() );
system(”cls”);
}

void Intro(void)
{
printf(”\n”);
printf(” * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n”);
printf(” *                                                             * \n”);
printf(” *                                         * *       * *       * \n”);
printf(” *                                       *     *   *     *     * \n”);
printf(” *     Wellcome Personal Phone Book..                          * \n”);
printf(” *                                               o             * \n”);
printf(” *                                        *             *      * \n”);
printf(” *                                          *         *        * \n”);
printf(” *           ______i     _____                 * * *           * \n”);
printf(” *          | ==== |    |  B  |                                * \n”);
printf(” *          | Any  |    |  O  ^         Ver2.4 – 2008/06/11    * \n”);
printf(” *          | Call |    |  O  ^                                * \n”);
printf(” *          |______|    |__K__|     blog – tyspace.tistory.com * \n”);
printf(” *                                            by. Kim Tae-Yong * \n”);
printf(” *                                         (tykim85@gmail.com) * \n”);
printf(” *                                                             * \n”);
printf(” * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n”);
}

void PrintTitle(void)
{
printf(”\n”);
printf(” * * * * * * * * * * * * * * * * * * * * * * * * \n”);
printf(” *                                             * \n”);
printf(” *     Personal Phone Book Program Ver2.4      * \n”);
printf(” *                                             * \n”);
printf(” *                   by. 0405059 Kim Tae Yong  * \n”);
printf(” *                                             * \n”);
printf(” * * * * * * * * * * * * * * * * * * * * * * * * \n”);
printf(”\n”);
printf(”\n”);
}

void MenuPrint(void)
{
printf(” === 메     뉴 === \n”);
printf(”\n”);
printf(”  1. 입     력 \n”);
printf(”  2. 검     색 \n”);
printf(”  3. 수정/삭제 \n”);
printf(”  4. 전체 보기 \n”);
printf(”  5. 종     료 \n”);
printf(”\n”);
printf(” 메뉴를 선택해주세요 (1-5) ? ”);
}

void ExitPrint(void)
{
PrintTitle();
printf(” — 종     료 — \n”);
printf(”\n”);
printf(” 정말 종료하시겠습니까 (Y/N) ? ”);
}

void AddList(LIST **dpHead, LIST **dpTail)
{
LIST *pNew = (LIST *) malloc (sizeof(LIST));
int mode=1, modify=0, choice;    /* 어떤항목입력모드?, 수정상태인가?, 어느거수정?    */
char yesno, temp;                /* 입력한 내용이 정확한가? , 그룹 입력 검사            */
char strGroup[3][7] = {”기타”, ”가족”, ”친구”};

while(mode != 0) {
PrintTitle();
switch(mode) {
case 1:
printf(” — 입     력 —\n”);
printf(”\n”);
/* 이름 필수 입력 */
while(1) {
printf(”  이름을 입력하세요 : ”);
gets(pNew->name);
fflush(stdin);
/* 입력받은 값이 없다면 에러를 출력하고 다시 입력받기 */
if( strlen(pNew->name) == 0 ) {
printf(”\n\n  !!! errer : 비워 둘 수 없습니다. !!!\n”);
cleaning(1.0);
continue;
}
else break;
}
if( modify == 0 ) mode = 2;
else mode = 5;
cleaning(1.0);
break;

case 2:
printf(” — 입     력 —\n”);
printf(”\n”);
/* 전화번호 필수 입력 */
while(1) {
printf(”  전화번호를 입력하세요 : ”);
gets(pNew->phone);
fflush(stdin);
/* 입력받은 값이 없다면 에러를 출력하고 다시 입력받기 */
if( strlen(pNew->phone) == 0 ) {
printf(”\n\n  !!! errer : 비워 둘 수 없습니다. !!!\n”);
cleaning(1.0);
continue;
}
else break;
}
if( modify == 0 ) mode = 3;
else mode = 5;
cleaning(1.0);
break;

case 3:
printf(” — 입     력 —\n”);
printf(”\n”);
/* 주소 입력 */
printf(”  E-mail을 입력하세요 : ”);
gets(pNew->mail);
fflush(stdin);
/* 입력받은 값이 없다면 ”None” 값 저장 */
if( strlen(pNew->mail) == 0 ) strcpy(pNew->mail, ”None”);
if( modify == 0 ) mode = 4;
else mode = 5;
cleaning(1.0);
break;

case 4:
printf(” — 입     력 —\n”);
printf(”\n”);
/* 그룹 입력 */
printf(”  그룹을 입력하세요 (1. 가족 | 2. 친구 | 0. 기타) : ”);
temp = getc(stdin);
fflush(stdin);
/* 입력받은 값이 없거나 0-2외의 수 입력시 default값 ’0’ 저장 */
if( temp == ’\n’ || temp == ’ ’ || temp < ’0’ || temp > ’9’ ) temp = ’0’;
pNew->group = atoi(&temp);
mode = 5;
cleaning(1.0);
break;

case 5:
/* 입력한 내용 확인하고 저장할지 새로 입력할지 결정 */
printf(” — 확     인 —\n”);
printf(”\n”);
printf(”  이    름 : %s\n”, pNew->name);
printf(”  전화번호 : %s\n”, pNew->phone);
printf(”  E – mail : %s\n”, pNew->mail);
printf(”  그    룹 : %s\n”, strGroup[pNew->group]);
printf(”\n”);
printf(” 위의 내용대로 저장 하시겠습니까 (Y/N) ? ”);
scanf(”%c”, &yesno);
fflush(stdin);
if( yesno == ’y’ || yesno == ’Y’ ) mode = 0;
else if( yesno == ’n’ || yesno == ’N’ ) {
mode = 6;
cleaning(1.0);
}
else {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
mode = 5;
cleaning(1.0);
}
break;

case 6:
modify = 1;
/* 새로 입력한다면 어느걸 새로 입력할건지 */
printf(” — 수     정 —\n”);
printf(”\n”);
printf(”  1. 이    름 수정\n”);
printf(”  2. 전화번호 수정\n”);
printf(”  3. E – mail 수정\n”);
printf(”  4. 그    룹 수정\n”);
printf(”  5. 저장안하고 메인으로\n”);
printf(”\n”);
printf(” 어떤 작업을 하시겠습니까 ? ”);
scanf(”%d”, &choice);
fflush(stdin);
if( choice < 1 || 5 < choice ) {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
mode = 6;
cleaning(1.0);
}
else if( choice == 5 ) {
printf(”\n\n  저장안하고 메인으로 돌아갑니다.\n”);
return;
}
else {
mode = choice;
cleaning(1.0);
}
break;
}
}
pNew->pNext = NULL;
pNew->pPrev = (*dpTail);
if( (*dpTail) != NULL ) {
(*dpTail)->pNext = pNew;
(*dpTail) = pNew;
}
else {
(*dpHead) = pNew;
(*dpHead)->pPrev = NULL;
(*dpTail) = (*dpHead);
}
}

LIST * SearchList(LIST **dpHead)
{
LIST *pList = (*dpHead);
char strGroup[3][5] = {”기타”, ”가족”, ”친구”};
char search[20];
char yesno;
int searchMode = 1;

/* 이름으로, 전화번호로 검색할지 선택 */
while(1) {
PrintTitle();
printf(” — 검     색 —\n”);
printf(”\n”);
printf(”  1. 이름으로   검색\n”);
printf(”  2. 전화번호로 검색\n”);
printf(”  3. 메인으로\n”);
printf(”\n”);
printf(”  선택해주세요 : ”);
scanf(”%d”, &searchMode);
fflush(stdin);
if( searchMode < 1 || 3 < searchMode ) {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}
else if( searchMode == 3 ) {
printf(”\n\n  메인으로 돌아갑니다.\n”);
pList = NULL;
return pList;
}
cleaning(1.0);
break;
}

/* 검색할 문자열 입력 */
while(1) {
PrintTitle();
printf(” — 검     색 —\n”);
printf(”\n”);
if( searchMode == 1 ) printf(”  검색할 이름을 입력하세요 : ”);
else printf(”  검색할 전화번호를 입력하세요 : ”);
gets(search);
fflush(stdin);
cleaning(1.0);
break;
}

/* 이름으로 검색할시 */
if( searchMode == 1 ) {
while(1) {
PrintTitle();
printf(” — 검     색 —\n”);
printf(”\n”);
if( strstr(pList->name, search) != NULL ) {
printf(”  \”%s\”을(를) 찾았습니다.\n\n”, pList->name);
printf(”  이    름 : %s\n”, pList->name);
printf(”  전화번호 : %s\n”, pList->phone);
printf(”  E – mail : %s\n”, pList->mail);
printf(”  그    룹 : %s\n”, strGroup[pList->group]);
printf(”\n\n  찾는 정보가 맞습니까 (Y/N) ? ”);
scanf(”%c”, &yesno);
fflush(stdin);
if( yesno == ’y’ || yesno == ’Y’ ) {
printf(”\n”);
system(”pause”);
return pList;
}
else if( yesno == ’n’ || yesno == ’N’ ) {
printf(”\n\n  계속 검색합니다.\n”);
pList = pList->pNext;
if( pList == NULL ) break;
cleaning(1.0);
continue;
}
else {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}
}
printf(”\n  \”%s\”을(를) 찾습니다.\n\n”, search);
printf(”\n\n  계속 검색합니다.\n”);
pList = pList->pNext;
if( pList == NULL ) break;
cleaning(1.0);
}
}
/* 전화번호로 검색할시 */
else {
while(1) {
PrintTitle();
printf(” — 검     색 —\n”);
printf(”\n”);
if( strstr(pList->phone, search) != NULL ) {
printf(”  \”%s\”을(를) 찾았습니다.\n\n”, pList->phone);
printf(”  이    름 : %s\n”, pList->name);
printf(”  전화번호 : %s\n”, pList->phone);
printf(”  E – mail : %s\n”, pList->mail);
printf(”  그    룹 : %s\n”, strGroup[pList->group]);
printf(”\n\n  찾는 정보가 맞습니까 (Y/N) ? ”);
scanf(”%c”, &yesno);
fflush(stdin);
if( yesno == ’y’ || yesno == ’Y’ ) {
printf(”\n”);
system(”pause”);
return pList;
}
else if( yesno == ’n’ || yesno == ’N’ ) {
printf(”\n\n  계속 검색합니다.\n”);
pList = pList->pNext;
if( pList == NULL ) break;
cleaning(1.0);
continue;
}
else {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}
}
printf(”\n  \”%s\”을(를) 찾습니다.\n\n”, search);
printf(”\n\n  계속 검색합니다.\n”);
pList = pList->pNext;
if( pList == NULL ) break;
cleaning(1.0);
}
}

/* 검색 내용이 없는 경우 */
system(”cls”);
PrintTitle();
printf(”\n\n  \”%s\”을(를) 찾지 못 하였습니다.\n\n”, search);
system(”pause”);
return pList;
}

void ModifyDelete(LIST **dpHead)
{
LIST *pPrevList;    /* 이전 리스트                    */
LIST *pList;        /* 현재 리스트                    */
LIST *pNextList;    /* 다음 리스트                    */
int choice, mode;    /* 메뉴선택, 어느걸 수정할지    */
char yesno, temp;    /* Y / N 선택, 그룹임시입력        */
char strGroup[3][5] = {”기타”, ”가족”, ”친구”};

while(1) {
PrintTitle();
printf(” — 수정/삭제 —\n”);
printf(”\n”);
printf(”  1. 수     정 \n”);
printf(”  2. 삭     제 \n”);
printf(”  3. 메인으로\n”);
printf(”\n”);
printf(”  선택해주세요 : ”);
scanf(”%d”, &choice);
fflush(stdin);
if( choice < 1 || 3 < choice ) {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}
else if( choice == 3 ) {
printf(”\n\n  메인으로 돌아갑니다.\n”);
return;
}
else {
cleaning(1.0);
break;
}
}

/* 수정/삭제 할 리스트 검색 */
pList = SearchList( &(*dpHead) );
if( pList == NULL ) return;
cleaning(1.0);
if( choice == 1 ) {
while(1) {
PrintTitle();
printf(” — 수     정 —\n”);
printf(”\n”);
printf(”  1. 이    름 수정\n”);
printf(”  2. 전화번호 수정\n”);
printf(”  3. E – mail 수정\n”);
printf(”  4. 그    룹 수정\n”);
printf(”\n”);
printf(” 어떤 작업을 하시겠습니까 ? ”);
scanf(”%d”, &choice);
fflush(stdin);
if( choice < 1 || 4 < choice ) {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}
else {
mode = choice;
cleaning(1.0);
}
switch(mode) {
case 1:
PrintTitle();
printf(” — 이름 수정 —\n”);
printf(”\n”);
/* 이름 필수 입력 */
while(1) {
printf(”  이름을 입력하세요 : ”);
gets(pList->name);
fflush(stdin);
/* 입력받은 값이 없다면 에러를 출력하고 다시 입력받기 */
if( strlen(pList->name) == 0 ) {
printf(”\n\n  !!! errer : 비워 둘 수 없습니다. !!!\n”);
cleaning(1.0);
continue;
}
else break;
}
printf(”\n\n  이    름 : %s\n”, pList->name);
printf(”  전화번호 : %s\n”, pList->phone);
printf(”  E – mail : %s\n”, pList->mail);
printf(”  그    룹 : %s\n”, strGroup[pList->group]);
printf(”\n\n 수정을 완료하시겠습니까 (Y/N) ? : ”);
scanf(”%c”, &yesno);
fflush(stdin);
if( yesno == ’y’ || yesno == ’Y’ ) {
printf(”\n\n  수정이 완료되었습니다.\n”);
return;
}
else if( yesno == ’n’ || yesno == ’N’ ) {
cleaning(1.0);
continue;
}
else {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}

case 2:
PrintTitle();
printf(” — 전화번호 수정 — \n”);
printf(”\n”);
/* 전화번호 필수 입력 */
while(1) {
printf(”  전화번호를 입력하세요 : ”);
gets(pList->phone);
fflush(stdin);
/* 입력받은 값이 없다면 에러를 출력하고 다시 입력받기 */
if( strlen(pList->phone) == 0 ) {
printf(”\n\n  !!! errer : 비워 둘 수 없습니다. !!!\n”);
cleaning(1.0);
continue;
}
else break;
}
printf(”\n\n  이    름 : %s\n”, pList->name);
printf(”  전화번호 : %s\n”, pList->phone);
printf(”  E – mail : %s\n”, pList->mail);
printf(”  그    룹 : %s\n”, strGroup[pList->group]);
printf(”\n\n 수정을 완료하시겠습니까 (Y/N) ? : ”);
scanf(”%c”, &yesno);
fflush(stdin);
if( yesno == ’y’ || yesno == ’Y’ ) {
printf(”\n\n  수정이 완료되었습니다.\n”);
return;
}
else if( yesno == ’n’ || yesno == ’N’ ) {
cleaning(1.0);
continue;
}
else {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}

case 3:
PrintTitle();
printf(” — E-mail 수정 — \n”);
printf(”\n”);
printf(”  E-mail을 입력하세요 : ”);
gets(pList->mail);
fflush(stdin);
/* 입력받은 값이 없다면 ”None” 값 저장 */
if( strlen(pList->mail) == 0 ) strcpy(pList->mail, ”None”);
printf(”\n\n  이    름 : %s\n”, pList->name);
printf(”  전화번호 : %s\n”, pList->phone);
printf(”  E – mail : %s\n”, pList->mail);
printf(”  그    룹 : %s\n”, strGroup[pList->group]);
printf(”\n\n 수정을 완료하시겠습니까 (Y/N) ? : ”);
scanf(”%c”, &yesno);
fflush(stdin);
if( yesno == ’y’ || yesno == ’Y’ ) {
printf(”\n\n  수정이 완료되었습니다.\n”);
return;
}
else if( yesno == ’n’ || yesno == ’N’ ) {
cleaning(1.0);
continue;
}
else {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}

case 4:
PrintTitle();
printf(” — 그룹 수정 — \n”);
printf(”\n”);
/* 그룹 입력 */
printf(”  그룹을 입력하세요 (1. 가족 | 2. 친구 | 0. 기타) : ”);
temp = getc(stdin);
fflush(stdin);
/* 입력받은 값이 없거나 0-2외의 수 입력시 default값 ’0’ 저장 */
if( temp == ’\n’ || temp == ’ ’ || temp < ’0’ || temp > ’9’ ) temp = ’0’;
pList->group = atoi(&temp);
printf(”\n\n  이    름 : %s\n”, pList->name);
printf(”  전화번호 : %s\n”, pList->phone);
printf(”  E – mail : %s\n”, pList->mail);
printf(”  그    룹 : %s\n”, strGroup[pList->group]);
printf(”\n\n 수정을 완료하시겠습니까 (Y/N) ? : ”);
scanf(”%c”, &yesno);
fflush(stdin);
if( yesno == ’y’ || yesno == ’Y’ ) {
printf(”\n\n  수정이 완료되었습니다.\n”);
return;
}
else if( yesno == ’n’ || yesno == ’N’ ) {
cleaning(1.0);
continue;
}
else {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}
}
}
}
else {
while(1) {
PrintTitle();
printf(” — 삭     제 — \n”);
printf(”\n”);
printf(”  이    름 : %s\n”, pList->name);
printf(”  전화번호 : %s\n”, pList->phone);
printf(”  E – mail : %s\n”, pList->mail);
printf(”  그    룹 : %s\n”, strGroup[pList->group]);
printf(”\n”);
printf(”\n 위 내용을 삭제 하시겠습니까 (Y/N) ? ”);
scanf(”%c”, &yesno);
fflush(stdin);
if( yesno == ’y’ || yesno == ’Y’ ) {
if( pList == (*dpHead) ) {
(*dpHead) = pList->pNext;
free(pList);
printf(”\n\n  삭제가 완료되었습니다.\n”);
return;
}
else if( pList->pNext == NULL ) {
pPrevList = pList->pPrev;
pPrevList->pNext = NULL;
free(pList);
printf(”\n\n  삭제가 완료되었습니다.\n”);
return;
}
pPrevList = pList->pPrev;
pNextList = pList->pNext;
pPrevList->pNext = pNextList;
pNextList->pPrev = pPrevList;
free(pList);
printf(”\n\n  삭제가 완료되었습니다.\n”);
return;
}
else if( yesno == ’n’ || yesno == ’N’ ) {
printf(”\n\n  삭제하지 않고 메인으로 돌아갑니다.\n”);
return;
}
else {
printf(”\n\n  !!! errer : 잘 못 선택하셨습니다. !!!\n”);
cleaning(1.0);
continue;
}
}
}
}

void PrintList(LIST **dpHead)
{
LIST *pList = (*dpHead);
char strGroup[3][5] = {”기타”, ”가족”, ”친구”}; /* 출력될 그룹명 */
int cnt = 1;

PrintTitle();
printf(” — 전체 보기 —\n”);
printf(”\n”);
printf(”  번호 이름            전화번호        E-mail                         그룹\n”);
printf(” ————————————————————————–\n”);
while( pList != NULL ) {
printf(”  %04d ”, cnt++);
printf(”%-15s ”, pList->name);
printf(”%-15s ”, pList->phone);
printf(”%-30s ”, pList->mail);
printf(”%-4s\n”, strGroup[pList->group]);
pList = pList->pNext;
}
printf(”\n”);
}

void Outtro(void)
{
system(”cls”);
PrintTitle();
printf(”\n\n  **  저희 프로그램을 이용해 주셔서 감사합니다.  **”);
printf(”\n\n  **  이용에 불편한 점 있으시면 아래 E-mail이나  **”);
printf(”\n\n  **  블로그를 통하여 알려주시기 바랍니다.       **”);
printf(”\n\n  **        by. Kim Tae-Yong (tykim85@gmail.com) **”);
printf(”\n\n  **            blog – tyspace.tistory.com       **\n\n”);
system(”pause”);
}

One thought to “[C언어] 주소록 (더블링크드리스트, 파일 입출력, 입력/검색/수정/삭제) P.P.B.P Ver2.4 소스”

댓글 남기기