게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
c언어 구조체 포인터 질문입니다 ㅠㅠ 도와주세요 ㅠㅠ
게시물ID : programmer_22726짧은주소 복사하기
작성자 : 슴여슷
추천 : 0
조회수 : 1641회
댓글수 : 4개
등록시간 : 2018/12/07 19:05:39
옵션
  • 본인삭제금지

typedef struct { // 재고 대장: 현재 보유하고 있는 Video 정보 저장  
char title[MAX_CHAR];
int qty; // 수량
} VideoInfo;

void printAllVideo(VideoInfo videoList[], int videoCount)
{
int i;

printf("Video제목\t수량\n");
printf("-------------------------\n");
for (i = 0; i < videoCount; i++)
printf("%s\t%d\n", videoList[i].title, videoList[i].qty);
}

void purchaseVideo(VideoInfo videoList[], int *videoCountPtr, char *title, int qty)
{
*videoList[*videoCountPtr].title = *title;
videoList[*videoCountPtr].qty = qty;
*videoCountPtr += 1;
}


int main(void)
{
int videoCount = 5;
VideoInfo videoList[MAX_VIDEO] = { {"BeforeSunrise", 1}, {"BeforeSunset", 3}, {"BeforeMidnight", 5}, {"Casablanca", 7}, {"EdgeOfTomorrow", 9} };
int rentCount = 0; // 현재 대출 건수는 0임
RentInfo rentList[MAX_CUST];


int choice;
int indexSearched;
char title[MAX_CHAR];
int custId, qty;


printf("1(All Video 출력), 2(구입), 3(검색), 4(대여), 5(All 대여정보 출력), 6(종료): ");
scanf("%d", &choice);

while (choice != 6) {
switch (choice) {
case 1:
printAllVideo(videoList, videoCount);
break;
case 2:
printf("Enter video 제목: ");
scanf("%s", title);
printf("Enter video 수량: ");
scanf("%d", &qty);
purchaseVideo(videoList, &videoCount, title, qty);
break;
}
printf("1(All Video 출력), 2(구입), 3(검색), 4(대여), 5(All 대여정보 출력), 6(종료): ");
scanf("%d", &choice);
}
}


질문 >>>


1. purchaseVideo함수 안에서
*videoList[*videoCountPtr].title = *title;
videoList[*videoCountPtr].qty = qty;
*videoCountPtr += 1;

라고 적었는데 title은 videoList앞에 포인터 형식을 넣지 않으면 빨간줄이 뜨고
qty는 포인터 형식을 넣지 않아도 괜찮습니다. 
이건 왜 이러는 건가요? ㅠㅠㅠㅠ



2. purchaseVideo함수를 위처럼 정의하고 난 뒤 빌드업을 하면
디버그 창에서 2(구입)을 선택 후 제목과 수량을 입력받는데

예를 들어 입력을 
제목: BeginAgain
수량: 10
이라고 입력한 후 AllVideo 출력을 다시 하면
(이미 저장되어 있는 것들은 다 정상적으로 뜨는데) 
B 10 이라고 뜹니다. 이건 왜 이러는 걸까요??ㅠㅠㅠ


식이 너무 길어서 보기 귀찮으실 수도 있지만 한번만 도와주시면 감사하겠습니다 ㅠㅠ
물어볼 곳이 없어서요 ㅠㅠ
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호