소스코드 분석좀
큰꽃들
질문 제목 : 질문 내용 :
[code]
#include stdio.h
#include stdlib.h
#include string.h
#define max 5
typedef enum thing{food=1, clothes=2, books=3}things;
typedef enum _boolean{true=1, false=0,error=-1}boolean;
typedef unsigned short int ushort;
ushort selectmenu();
void buysomething(ushort thing, ushort *capacity, char (*inventory)[10]);
ushort isbelowfive (ushort capacity);
void showinventory (char (*inventory)[10]);
int main() {
ushort thing;
ushort capacity=0;
char (*inventory)[10] = (char(*)[10]) calloc (max, sizeof(char));
while(capacity != -1) {
thing = selectmenu();
buysomething(thing, &capacity, inventory);
capacity = isbelowfive(capacity);
}
showinventory(inventory);
return 0;
}
ushort selectmenu() {
int choice;
printf(1 음식 2 옷 3 책 :);
scanf(%d, &choice);
return (ushort)choice;
}
void buysomething(ushort thing, ushort *capacity, char (*inventory)[10]) {
switch(thing) {
case food:
(*capacity)++;
strcpy(inventory[*capacity], food);
break;
case clothes:
(*capacity)++;
strcpy(inventory[*capacity], clothes);
break;
case books:
(*capacity)++;
strcpy(inventory[*capacity], books);
break;
}
}
ushort isbelowfive (ushort capacity) {
if(capacity==5) {
printf(장바구니 꽉찼다.. \n);
return -1;
}
}
void showinventory (char (*inventory)[10]) {
int i;
for(i=0; imax; i++) {
printf(%s \n, inventory[i]);
}
}
[/code]
return 해서 -1이 됬는데도 안끝나네요 --/.
-
BabySue
while 반복문 조건이 (capacity != -1) 요거인데 계속 만족중이니 계속 반복합니다.
-
앵초
크으;;; 가독성이;;;
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2698184 | 간단한 C언어 인데 .. | 붕붕 | 2025-06-14 |
2698120 | -연산자 가 먼지 좀 알려주세요 (1) | 낮선검객 | 2025-06-14 |
2698091 | 길찾기문제 질문이요! | 노을빛 | 2025-06-13 |
2698060 | while 문에 대한 질문입니다. (9) | 물고기자리 | 2025-06-13 |
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 |