고수분들 도와주세요 ㅠㅠㅠ
BabySue
질문 제목
포인터를 안쓰면 쉽게 하는데 꼭 구조체배열포인터를 함수전달인자로 받으라고 해서요 ㅠㅠ:
이름, 나이, 키, 몸무게를 멤버로 하는 구조체를 이용하여 사람 신상 정보를 찾는 프로그램 작성. 로컬변수, 로컬배열, 로컬구조체만 사용.
- main함수, menu함수, name함수, age함수, height함수, weight함수, result함수를 작성
- main함수에 요소수가 5개인 구조체 배열을 선언하고 아래 데이터를 이용하여 초기화 함.
kim, 39, 170, 75
jung, 60, 155, 55
lee, 20, 165, 60
hong, 40, 173, 70
park, 25, 164, 52
- menu함수를 이용하여 다음과 같이 모니터에 출력하고 사용자로부터 원하는 번호를 입력 받음. 사용자가 ‘5) quit’을 선택했을 때만 프로그램이 종료되어야 함
-----------------------------
1) search by name
2) search by age
3) search by height
4) search by weight
5) quit
-----------------------------
select the number:
- name함수는 입력된 번호가 1번일 때 다음과 같은 문장을 모니터에 출력시켜 찾고자 하는 사람의 이름을 입력 받음. 예) 사용자가 1번을 선택했을 경우 ‘enter the name:’ 또한 구조체배열포인터를 인수로 받아 위 구조체와 사용자가 입력한 이름으로 사람을 찾음.
- age함수도 마찬가지며 ‘enter the age:’를 출력하고 구조체배열포인터를 인수로 받아 입력한 나이로 사람을 찾음.
- height함수도 마찬가지며 ‘enter the height:’를 출력하고 구조체배열포인터를 인수로 받아 입력한 키로 사람을 찾음.
- weight함수도 마찬가지며 ‘enter the weight:’를 출력하고 구조체배열포인터를 인수로 받아 입력한 몸무게로 사람을 찾음.
- result함수는 위에서 찾은 사람의 정보를 다음과 같이 모니터에 출력함. 예) 키 165를 입력했을 경우 lee 30 years 165cm 60kg 출력. 찾는 사람이 없을 경우 ‘there is no such person.’이라는 메시지 출력일단 네임부문 만 하다가 말았음 오류만 계쏙 생기고 그래서여 ㅡㅡ
#include stdio.h
#include string.h
void menu();
void name(struct testrecord *students, struct testrecord *p );
struct testrecord
{
char name[80];
int age;
int height;
int weight;
};
int main(int argc, char *argv[])
{
int i, c;
struct testrecord students[5];
struct testrecord *p;
strcpy(students[0].name, kim);
students[0].age=39;
students[0].height=170;
students[0].weight=75;
strcpy(students[1].name, jung);
students[1].age=60;
students[1].height=155;
students[1].weight=55;
strcpy(students[2].name, lee);
students[2].age=20;
students[2].height=165;
students[2].weight=60;
strcpy(students[3].name, hong);
students[3].age=40;
students[3].height=173;
students[3].weight=70;
strcpy(students[4].name, park);
students[4].age=25;
students[4].height=164;
students[4].weight=52;
menu();
scanf(%d, c);
if(c==1)
{
printf(enter the name : );
scanf(%s, &p);
name(&struct testrecord students, &p);
}
}void menu()
{
printf(--------------------------\n\n);
printf(1)search by name\n);
printf(2)search by age\n);
printf(3)search by height\n);
printf(4)search by weight\n);
printf(5)quit\n\n);
printf(--------------------------\n\n);
printf(select the number : );
}
void name(struct testrecord *students, struct testrecord *p)
{
int i;
for(i=0; i5; i++)
{
if(struct testrecord *p == struct testrecord students[i].name);
{
p=&students[i];
printf(이름은 %s\n,p-name);
break;
}
}
}
-
한누리
답변좀해주세요 ㅠㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2698012 | 2~9가아닌수 | 아놀드 | 2025-06-13 |
2697980 | for에 gets함수를 넣으니까 왜 반복이 안되죠 ㅜ (2) | 펴라 | 2025-06-12 |
2697952 | 2차배열과 함수문의^^; | VanilLa | 2025-06-12 |
2697924 | 다차원 배열 질문있습니다 | 두동 | 2025-06-12 |
2697893 | 정올 :: 기초다지기 a9007 배열7 (문제가 이상함 -_-) | 흰두루 | 2025-06-12 |
2697862 | Unable......... 지정된 파일을 찾을 수 없습니다!! (1) | Creator | 2025-06-11 |
2697761 | 그러니까여제말은... (2) | 새론 | 2025-06-10 |
2697737 | 정올 문제좀 풀어보신분~ | 레오 | 2025-06-10 |
2697709 | rand함수 질문좀요! (6) | 가막새 | 2025-06-10 |
2697683 | C언어 변수뒤 표시가 이해안되는게 있습니다. | 소미 | 2025-06-10 |
2697660 | 껍데기딜 만들고 난후 어느핫키 누르면 코드검색이라도 뜨고 그다음 무반응 해결좀 (2) | 움찬 | 2025-06-09 |
2697634 | c언어로 감성사전 만들기! (1) | 도란도란 | 2025-06-09 |
2697605 | 이 함수좀... | agine | 2025-06-09 |
2697574 | 배열 기본적인질문 (3) | 민트향 | 2025-06-09 |
2697549 | 배열 초기화 (4) | 나리 | 2025-06-08 |
2697465 | 수다님...^^ (2) | 가론 | 2025-06-08 |
2697432 | 서버 만드는 함수에서 궁금한게있어요~ | 파랑 | 2025-06-07 |
2697401 | 열혈강의 문제오류 (1) | 꿈 | 2025-06-07 |
2697374 | 기초적인 C언어 프로그래밍 입니다. | 얼 | 2025-06-07 |
2697341 | 좌우대칭 문제인데 Q가 입력되면 종료가 되야하는데 되지않습니다 | 무지개 | 2025-06-07 |