이 코드 돌려서 입력 계속하면 입력된게 계속 쌓여야 되는데
입력 할때마다 마지막 한개만 남네..
문제가 뭔지 -_-...
짤은 조공..
#include <stdio.h>
#include <stdlib.h>
typedef struct STUDENT
{
char name[50],adress[100];
int PN[10],STN[10];
float grade[10];
struct STUDENT *prev;
struct STUDENT *next;
}st;
st *head=NULL; //node pointer
st *tail=NULL;
//initialization
void initi()
{
head=(st*)malloc(sizeof(st));
tail=(st*)malloc(sizeof(st));
head->next=tail;
head->prev=head;
tail->prev=head;
tail->next=tail;
}
void insertnode(st *insert)
{
st *newnode;
newnode=(st*)malloc(sizeof(st));
newnode = insert;
tail->prev->next=newnode;
newnode->prev=tail->prev;
tail->prev=newnode;
newnode->next=tail;
}
void show_print()
{
st *tmp;
tmp=head->next;
while(tmp != tail)
{
printf("-----------------------------------------------------------------\\n");
printf(" Name | Student ID | Adress | Phone Number | Grade |\\n");
printf("-----------------------------------------------------------------\\n");
{
printf("%12s|", tmp->name);
printf("%12d|", *tmp->STN);
printf("%12s|", tmp->adress);
printf("%12d|", *tmp->PN);
printf("%12f|\\n", *tmp->grade);
}
printf("-----------------------------------------------------------------\\n");
tmp=tmp->next;
}
}
struct MAJOR
{
char name[500];
int PN[10];
};
struct PROFESSOR
{
char name[500],adress[500];
int PN[10],EN[10];
};
int main(void)
{
// st *std;
st *copy;
int mode;
int i=1, m;
//std = (struct STUDENT*)malloc(sizeof(std)*i);
copy = (struct STUDENT*)malloc(sizeof(st));
initi();
for(;;){
printf("#########################################\\n");
printf("#\\tGrade management programs\\t#\\n");
printf("# 1. Registration of student\\t\\t#\\n");
printf("# 2. List of registered student\\t\\t#\\n");
printf("# 3. Registration of professor\\t\\t#\\n");
printf("# 4. List of registered professor\\t#\\n");
printf("# 5. Registration of major\\t\\t#\\n");
printf("# 6. List of registered major\\t\\t#\\n");
printf("# 7. EXIT\\t\\t\\t\\t#\\n");
printf("#########################################\\n");
printf("Select mode : ");
scanf("%d", &mode);
if(mode==1){
printf("Enter Student name : ");
scanf("%s", copy->name);
printf("Enter Student ID : ");
scanf("%d", copy->STN);
printf("Enter Adress : ");
scanf("%s", copy->adress);
printf("Enter Phone number : ");
scanf("%d", copy->PN);
printf("Enter Grade : ");
scanf("%f", copy->grade);
insertnode(copy);
printf(" registration of %d student\\n", i);
i++;
}
else if(mode==2){
show_print();
}
else if(mode==7){
printf("Bye\\n");
break;
}
}
free(copy);
return 0;
}
댓글 영역
획득법
① NFT 발행
작성한 게시물을 NFT로 발행하면 일주일 동안 사용할 수 있습니다. (최초 1회)
② NFT 구매
다른 이용자의 NFT를 구매하면 한 달 동안 사용할 수 있습니다. (구매 시마다 갱신)
사용법
디시콘에서지갑연결시 바로 사용 가능합니다.