수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

구조체와 포인터 오류좀 봐주세요 ...

휘들램

2023.04.01

질문 제목 : 구조체 멤버변수들을 포인터를 이용(배열 사용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
}
}

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
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
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com