성적관리에서 삭제좀 도와주세요...
개굴츼
질문 제목 : 질문 내용 :
#include stdio.h
#include string.h// 문자열 관련 표준함수 정의. strcmp() 등
#include process.h
#define max_name 20
#define max_id 20
#define max_students 5
struct score {
unsigned int kor;// 국어
unsigned int eng;// 영어
unsigned int math;// 수학
double avg;// 평균
unsigned int rank;// 순위
};
struct student{
char name[max_name];// 이름
char id[max_id];// 아이디
struct score scores;// score 구조체 변수
};
void show()
{
printf(\t\t\t┌─────────┐\n);
printf(\t\t\t│성적 관리 프로그램│\n);
printf(\t\t\t└─────────┘\n);
}
void inputdata(struct student* st,int index)
{
printf( ★ 자료입력 ★\n);
printf( 이름 : );scanf(%s,st[index].name);
printf( i d : );scanf(%s,st[index].id);
printf( 국어 : );scanf(%d,&st[index].scores.kor);
printf( 영어 : );scanf(%d,&st[index].scores.eng);
printf( 수학 : );scanf(%d,&st[index].scores.math);
st[index].scores.avg = ((double)st[index].scores.eng+(double)st[index].scores.kor+(double)st[index].scores.math)/3;
}
void showdata(struct student* st,int index)
{
int i;
printf(┌───────────────────────────────────┐\n);
printf(│이름 \t id\t\t 국어\t 영어\t 수학\t 평균\t 순위\t│\n);
printf(├───────────────────────────────────┤\n);
for(i=0; iindex ;i++)
{
printf(│%s \t %s \t %d\t %d\t %d\t %2.2lf\t %d\t│\n,st[i].name,st[i].id,st[i].scores.kor,st[i].scores.eng,st[i].scores.math,st[i].scores.avg,st[i].scores.rank);
}
printf(└───────────────────────────────────┘\n);
}
void rank(struct student* st,int index)
{
int i,j;
for(i=0;iindex;i++)
{
st[i].scores.rank=1;
for(j=0;jindex;j++)
{
if(st[i].scores.avg st[j].scores.avg)
{
st[i].scores.rank++;
}
}
}
}
int searchbyint(struct student* st,int index, char* findname)
{
int i;
for(i=0; iindex; i++)
{
if(strcmp(st[i].name,findname)==0)
{
return i;
}
}
return -5;
}
void searchdata(struct student* st, int index)
{
char findname[max_name];
int pos;
printf( ★ 검색 이름 : );scanf(%s,findname);
pos=searchbyint(st,index,findname);
if(pos!=-5)
{
printf(┌───────────────────────────────────┐\n);
printf(│이름 \t id\t\t 국어\t 영어\t 수학\t 평균\t 순위\t│\n);
printf(├───────────────────────────────────┤\n);
printf(│%s \t %s \t %d\t %d\t %d\t %2.2lf\t %d\t│\n,st[pos].name,st[pos].id,st[pos].scores.kor,st[pos].scores.eng,st[pos].scores.math,st[pos].scores.avg,st[pos].scores.rank);
printf(└───────────────────────────────────┘\n);
}
else
{
printf(입력하신 이름이 없습니다.\n);
}
}
void delete(struct student*st,int index)br /ex)
{
char findname[max_name];
int i,j;
int del;
printf( ★ 삭제 이름 : );scanf(%s,findname);
del=searchbyint(st,index,findname);
if(del !=-5)
{
for(i=del;iindex;i++)
{
for(j=del+1;jindex;j++)
{
strcpy(st[i].name,st[j].name);
strcpy(st[i].id,st[j].id);
st[i].scores.kor=st[j].scores.kor;
st[i].scores.eng=st[j].scores.eng;
st[i].scores.math=st[j].scores.math;
st[i].scores.avg=st[j].scores.avg;
st[i].scores.rank=st[j].scores.rank;
}
}
index--;
}
}
void change(struct student* st,int index)
{
char findname[max_name];
int pos1;
printf( ★ 성적 정정 : ); scanf(%s,findname);
pos1=searchbyint(st,index,findname);
if(pos1!=-5)
{
printf( ┌─────┐\n);
printf( │정정 입력 │\n);
printf( └─────┘\n);
printf( 이름 : );scanf(%s,st[pos1].name);
printf( i d : );scanf(%s,st[pos1].id);
printf( 국어 : );scanf(%d,&st[pos1].scores.kor);
printf( 영어 : );scanf(%d,&st[pos1].scores.eng);
printf( 수학 : );scanf(%d,&st[pos1].scores.math);
st[pos1].scores.avg = ((double)st[pos1].scores.eng+(double)st[pos1].scores.kor+(double)st[pos1].scores.math)/3;
}
else
{
printf(입력하신 이름이 없습니다.\n);
}
}
int main(void)
{
struct student st[100];
int select;
int index=0;
while(1)
{
show();
printf( ┌───────┐\n);
printf( │ 1. 성적 입력 │\n);
printf( │ 2. 성적 출력 │\n);
printf( │ 3. 성적 검색 │\n);
printf( │ 4. 성적 수정 │\n);
printf( │ 5. 성적 삭제 │\n);
printf( │ 0. 종료 │\n);
printf( └───────┘\n);
printf( ★ 선택 : );scanf(%d,&select);
system(cls);
rank(st,index);
switch(select)
{
case 1:
show();
inputdata(st,index);
index++;
system(pause);
system(cls);
break;
case 2:
show();
showdata(st,index);
system(pause);
system(cls);
break;
case 3:
show();
searchdata(st,index);
system(pause);
system(cls);
break;
case 4:
show();
change(st, index);
system(pause);
system(cls);
break;
case 5:
show();
delete(st, index);
system(pause);
system(cls);
break;
case 0:
show();
system(pause);
return 0;
}
}
return 0;
}
이렇게 했는데 삭제가 잘 되지 않네요.. 삭제를 어떻게 해야하는지... 쩝..
좀 가르쳐주세요
-
빛초롱
연결리스트로 하시는게 훨씬 좋을텐데요
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2699272 | printf() 함수이용해서 프로그램 만들기 질문요! (5) | 다가 | 2025-06-24 |
2699221 | PUSH와 POP코드를 더 간단하게 어떻게 해야할까요? | 파라미 | 2025-06-24 |
2699192 | 설치오류가 자꾸 나요 한번봐주세여~ (1) | 소녀틳향기 | 2025-06-23 |
2699161 | for loop안에 있는 if문 (9) | Orange | 2025-06-23 |
2699105 | 링크더리스트 이전 링크값 출력함수. | 꼬꼬마 | 2025-06-23 |
2699078 | 정수를 한자리씩 배열에 담는 법은 어떻게 하나요.. (4) | 귀염포텐 | 2025-06-22 |
2699024 | C언어 공부하려는데 도와주세요!!! (2) | 달님 | 2025-06-22 |
2698994 | 날짜 계산하는 C 코드 짜고 있는데 꽉 막혀서 질문드립니다.. (6) | 별 | 2025-06-22 |
2698967 | 파일삭제 윈도우 폴더까지 접근하게하는 함수가 뭔가요 (2) | 샤인 | 2025-06-21 |
2698938 | c언어 메모리질문 (3) | 나래 | 2025-06-21 |
2698909 | 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) | 궁수자리 | 2025-06-21 |
2698882 | 프로그래밍좀 짜주세요 (3) | 황예 | 2025-06-21 |
2698855 | 카프-라빈 알고리즘 코딩 분석좀 도와주세요.. | 꽃봄 | 2025-06-20 |
2698829 | 학점계산기 (7) | MyWay | 2025-06-20 |
2698782 | 기초적인 함수 질문이요ㅠㅠㅠㅠ | 내담 | 2025-06-20 |
2698749 | 프로그램 짜던 도중 패닉입니다...ㅜ | 파랑 | 2025-06-19 |
2698719 | 조건부컴파일 질문입니다.~ (2) | 큐트 | 2025-06-19 |
2698693 | 재귀 함수 에러 | 바닐라 | 2025-06-19 |
2698673 | 고민이있는데 들어좀주세요!! (1) | 초코맛캔디 | 2025-06-19 |
2698644 | 1부터 n까지의 합을 구하는데 엄청긴숫자의 합을 구할때는 어떻게 해야하나요? (4) | 슬우 | 2025-06-18 |