#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct LIST{
char _name[10];
int _age;
struct LIST* next;
};
LIST* head;
void createLIST()
{
LIST* newList = (LIST*)malloc(sizeof(LIST));
LIST* temp;
char name[10];
int age;
printf("이름 : ");
scanf("%s",name);
fflush(stdin);
printf("나이 : ");
scanf("%d: ",&age);
strcpy(newList->_name,name);
newList->_age = age;
newList->next =NULL;
temp = head;
while(temp->next != NULL)
{
temp = temp->next;
}
if(head->next == NULL){
head->next = newList;
}else{
temp->next = newList;
}
}
void printLIST()
{
LIST* p = head->next;
for(;p;p=p->next){
printf("%s %d\n",p->_name,p->_age);
}
}
void deleteLIST()
{
char dname[10];
LIST* temp;
LIST* temp2;
temp = head;
printf("삭제 하실 이름 : ");
scanf("%s",dname);
while(temp->next != NULL)
{
if(strcmp(temp->next->_name,dname)==0) break;
temp = temp->next;
}
temp2 = temp->next->next;
free(temp->next);
temp->next = temp2;
}
void searchLIST()
{
char dname[10];
LIST* temp;
temp = head;
printf("검색 하실 이름 : ");
scanf("%s",dname);
while(temp->next != NULL)
{
if(strcmp(temp->_name,dname)==0) break;
temp = temp->next;
}
printf("이름 : %s 나이 %d\n",temp->_name,temp->_age);
}
void main()
{
int flag=0;
head = (LIST *)malloc(sizeof(LIST));
head->next = NULL;
while(1){
printf("추가 1 / 삭제 2 / 검색 3 / 모두보기 4\n입력 ::");
scanf("%d",&flag);
switch(flag){
case 1:
createLIST();
break;
case 2:
deleteLIST();
break;
case 3 :
searchLIST();
break;
case 4 :
printLIST();
break;
default :
printf("잘못 입력하셧습니다.\n");
}
}
}
'Study > C / C++' 카테고리의 다른 글
API 비행기 출력 소스 (0) | 2014.09.12 |
---|---|
API 도형 그리기 (0) | 2014.09.11 |
Cpp / 스택을 이용한 주소록 (0) | 2014.09.05 |
Black Jack ver.2 (0) | 2014.09.04 |
C언어를 이용한 Black Jack 게임 (1) | 2014.09.04 |