수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • 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

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

번호 제 목 글쓴이 날짜
2700287 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) 아련나래 2025-07-03
2700264 문자와 숫자 동시에 입력??? 글고운 2025-07-03
2700236 txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) 미국녀 2025-07-03
2700211 전위 연산자 (2) 어른처럼 2025-07-02
2700183 C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; 피스케스 2025-07-02
2700150 꼭좀 도와주세요ㅠㅠㅠ 호습다 2025-07-02
2700095 연산문제...질문... 오빤테앵겨 2025-07-01
2700070 while문 , 3의배수 출력하는 프로그램좀 짜주세욤. 횃불 2025-07-01
2700041 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? 헛장사 2025-07-01
2700012 배열// (1) 전갈자리 2025-07-01
2699895 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) 선아 2025-06-30
2699842 질문을 너무 많이 하네여.....죄송.... (2) 해님꽃 2025-06-29
2699816 오류 질문입니다.. (1) 해비치 2025-06-29
2699763 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) 미라 2025-06-28
2699555 c언어 다항식을 입력을 했는데 왜 출력이 안될까요? 피스케스 2025-06-27
2699528 C언어 포인터연산 질문입니다. (3) 안녕나야 2025-06-26
2699476 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) 클라우드 2025-06-26
2699444 [좀 급함] system("explorer [주소] ") 문에 변수를 사용할 수 있나요? 알 2025-06-26
2699415 파일//read//와 배열 아란 2025-06-25
2699386 구조체 안에 일부분만 char 배열에 복사하려면 어떻게 해야하나요? (1) 미즈 2025-06-25
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

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