구조체와 포인터 오류좀 봐주세요 ...
휘들램
질문 제목 : 구조체 멤버변수들을 포인터를 이용(배열 사용x)하여 정렬하는문제라고 생각됩니다.
질문 요약 :struct student *next;는struct변수의 다음 변수로 이동 하는것입니다.
포인터가 struct 변수의 주소 를 저장하고 struct 변수를 포인터를 이용해서 정렬합니다.
제가 해보긴 했으나 오류가 좀 나오는데 고치기가 어렵네요.
오류좀 봐주세요.
질문 내용 :
#include stdio.h
struct student {
int number;
char name[10];
double height;
struct student *next;
};
void bubblesort(struct student *current);
int main(void)
{
struct student s1={1, B,190.1,NULL};// 넘버,이름,키
struct student s2={4, A,161.2,NULL};
struct student s3={3, C,152.3,NULL};
struct student s4={2, E,173.4,NULL};
struct student s5={9, D,154.5,NULL};
struct student s6={6, F,175.6,NULL};
struct student s7={10, H,186.7,NULL};
struct student s8={8, G,186.8,NULL};
struct student s9={5, J,184.9,NULL};
struct student s10={7, I,183.1,NULL};
struct student *first =NULL;
struct student *current = NULL;
first = &s1;
s1.next =&s2;
s2.next =&s3;
s3.next =&s4;
s4.next =&s5;
s5.next =&s6;
s6.next =&s7;
s7.next =&s8;
s8.next =&s9;
s9.next =&s10;
s10.next = NULL;
current = first;
while(current != NULL)
{
printf(정렬전 학생 번호 =%d\n 이름 =%s\n 키=%lf\n,current-number, current-name ,current-height);
current = current-next;
}
bubblesort(current);
while(current != NULL)
{
printf(정렬후 학생 번호 =%d\n 이름 =%s\n 키=%lf\n,current-number, current-name ,current-height);
current = current-next;
}
}
void bubblesort(struct student *current)
{
int least,temp;
/* int* pnumber = &(current-number);
double* pheight = &(current-height);
char* pname = &(current-name); 오류를 없애는데 사용하려고 만들었으나 못써봄...*/
while(current-next != NULL)//current가 NULL이 될때까지 반복
{
for( &(current-number) != NULL)//s1~10.number값 정렬하는 포문
{
least = current-number;
if(least current-number )
{
temp = current-number;
current-number = least;
least = temp;
}
current = current-next;
}
for( &(current-height) != NULL)//s1~10.height값 정렬하는 포문
{
(double)least = current-height;
if(least current-height )
{
temp = current-number;
current-height = least;
least = temp;
}
current = current-next;
}
for( &(current-name) !=NULL)//s1~10.name값 정렬하는 포문
{
(char)least = current-name;
if(least current-name)
{
temp = current-number;
current-name = least;
least = temp;
}
current = current-next;
}
current = current-next;//while 증감문 s1~s10
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2694258 | 카운터.. 질문입니다. (4) | 하늘빛눈망울 | 2025-05-09 |
2694229 | 단순한 질문이요 (8) | 여름 | 2025-05-09 |
2694202 | 용돈을 가지고 할 수 있는 일을 여러가지로 출력하는 방법 좀 알려주세요! (2) | 미나 | 2025-05-09 |
2694145 | 화면깜빡임을 없애고 싶은데요... (1) | 어서와 | 2025-05-08 |
2694069 | unsigned 질문입니다. | 힘차 | 2025-05-07 |
2694012 | 전공 비전공자 개발자 (10) | 말글 | 2025-05-07 |
2693984 | 오버로딩이 무엇인가요? (2) | 헛매질 | 2025-05-07 |
2693956 | PlaySound재생이 안됩니다!(C에 음악넣기) | 지존 | 2025-05-06 |
2693928 | &와 *의 사용에 관한 명확한 이해 | 제나 | 2025-05-06 |
2693903 | 반복문 설명좀요 ㅠㅠ (2) | 란새 | 2025-05-06 |
2693869 | stdio.h 는 왜 쓰는건가요? (1) | 큰꽃들 | 2025-05-06 |
2693842 | 포인터 변수의 주소값끼리 더하는 것에 대해서 질문드립니다. (1) | 진솔 | 2025-05-05 |
2693811 | 소수 출력;;;; | 화이트캣 | 2025-05-05 |
2693788 | 이런 함수는 없나요? (3) | 앤드류 | 2025-05-05 |
2693758 | txt파일 불러와서 행렬로 저장 | 큰애 | 2025-05-05 |
2693727 | scanf 오류 문제!! (2) | 큰나래 | 2025-05-04 |
2693704 | 구조체 주소록 문제인데 도와주세요 (2) | 도1도캣 | 2025-05-04 |
2693676 | 열혈강의 c언어 질문입니다 | 하양이 | 2025-05-04 |
2693647 | 12.620000 을요 12.620 으로 어떻게 표현해요? (2) | 파도 | 2025-05-04 |
2693619 | 타이틀 코드.. | 단순드립 | 2025-05-03 |