소스를 작성해서 돌리니까 원인을 잘 모르겠습니다. 도와주세요
희미한눈물
비주얼 스튜디오2008로 돌리니 이렇게 오류가 뜬 사진 입니다.
프로그램을 작성을 돌렸는데이렇게 뜨는데해결을 어떻게 해야할지 도움이 필요합니다. ㅠ.ㅠ#include stdio.h
#include stdlib.h// 구조체 정의
typedef struct student_tag{
int ID;
char name[32];
char hobby[128];
} student;
// 함수헤더
student* SaveStudents(int count);
void PrintStudents(student* ptrStudent, int count);
int main()
{
int number = 3;
// 요청만큼의 학생정보가 담긴 구조체 배열 반환
student* ptrStudent = SaveStudents(number);
// 입력된 학생카드 출력
PrintStudents(ptrStudent, number);
// 리소스 해제
free(ptrStudent);
return 0;
}
// 학생카드를 저장합니다.
student* SaveStudents(int count)
{
// 구조체 배열을 동적으로 메모리 할당
student* students = (student*)malloc(sizeof(student) * count);
printf(--------------------------------\n);
printf(%d명의 학생 기록를 입력하세요. \n, count);
printf(--------------------------------\n); // 포인터 연산으로 구조체 접근 (students + loop)-
for(int loop = 0; loop count; loop++)
{
// ID 자동부여
(students + loop)-ID = loop + 1;
printf(ID: %d \n, (students + loop)-ID);
// 이름
printf(이름: );
scanf(%s, (students + loop)-name);
// 취미
printf(취미: );
scanf(%s, (students + loop)-hobby);
printf(\n);
}
// 할당받은 구조체 배열의 포인터 반환
return students;
}
// 학생카드를 출력합니다.
void PrintStudents(student* ptrStudent, int count)
{
printf(\n\n\n);
printf(--------------------------------\n);
printf(학생카드 \n);
printf(--------------------------------\n);
for(int loop = 0; loop count; loop++)
{
printf(id : %d \n, (ptrStudent + loop)-ID);
printf(name : %s \n, (ptrStudent + loop)-name);
printf(hobby: %s \n, (ptrStudent + loop)-hobby);
printf(\n\n);
}
printf(\n\n\n);
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2697465 | 수다님...^^ (2) | 가론 | 2025-06-08 |
2697432 | 서버 만드는 함수에서 궁금한게있어요~ | 파랑 | 2025-06-07 |
2697401 | 열혈강의 문제오류 (1) | 꿈 | 2025-06-07 |
2697374 | 기초적인 C언어 프로그래밍 입니다. | 얼 | 2025-06-07 |
2697341 | 좌우대칭 문제인데 Q가 입력되면 종료가 되야하는데 되지않습니다 | 무지개 | 2025-06-07 |
2697314 | fprintf와 fscanf 로 파일 입출력 할떄 | 밝음이 | 2025-06-06 |
2697293 | 툴 소스 뽑아내는법 | 도움 | 2025-06-06 |
2697264 | 소소한거 두어가지 질문할께요~ (8) | 별솔 | 2025-06-06 |
2697235 | scanf로 인풋 받을 때?! | 보담 | 2025-06-06 |
2697207 | 열혈강의 연습문제 질문이요~ (2) | 맥적다 | 2025-06-05 |
2697182 | strcmp, strtok - 어떤 기능을 하는지... | 루다 | 2025-06-05 |
2697129 | [질문] 아래 저축액을 계산하는 프로그램 ㅠ 추가 질문 (7) | 찬늘 | 2025-06-05 |
2697072 | 쌩초보 질문! (1) | 얀 | 2025-06-04 |
2697050 | 도움부탁드립니다.. | 화이트 | 2025-06-04 |
2697023 | gotoxy함수, 어떻게 사용하죠? (3) | 적송 | 2025-06-04 |
2696994 | c언어를 막 시작한 초보인데 질문이 있어용 ㅠㅠ (2) | 귀1여운렩 | 2025-06-03 |
2696944 | 윈도우 콘솔프로그램 질문드립니다 (2) | 꽃님이 | 2025-06-03 |
2696882 | c언어 입력받기 질문 입니다 (2) | 흰추위 | 2025-06-02 |
2696853 | 문자열은 정적메모리에 할당된다고 하는데 정적메모리가 뭡니까?? (6) | 다온 | 2025-06-02 |
2696799 | c c++언어입문전에 파이톤이나 자바스크립트배워두면.. (2) | 앨런 | 2025-06-02 |