구조체 검색 소스 수정 좀 부탁드립니다.
BabySue
질문 제목 : 구조체 검색 도와주세요구조체 검색후에 프로그램이 종료가 되면 안되는데 종료가 됩니다. 어떻게 해야하죠질문 내용 :
안녕하세요 아래 소스는 제품명, 이름, 전화번호, 날짜를 입력받고 출력하고, 검색해아하는 소스인데요
입 출력은 문제없고 검색부분에서 검색도 되는데
검색 후에 분기문으로 돌아가고싶은데 프로그램이 종료가 됩니다.
check=1
if(check==0) 부분도 검색때문에 붙이긴했는데 마음에 안드네요 ㅠㅠ 어떻게해야하나요.
#include stdio.h
#include string.h
struct as {
char product[20];
intdate;
char customer[10];
char tel[20];
};
void input_item(struct as [], int);
void output_items(struct as [], int);
void search(struct as[], int);
void main()
{
struct as item[100];
int menu, total = -1;
while (1) {
printf(\n메뉴 (1: 입력, 2: 출력, 3: 검색, 4: 종료) ? );
scanf(%d, &menu);
fflush(stdin);
switch (menu) {
case 1:
total = total + 1;
input_item(item, total);
break;
case 2:
output_items(item, total);
break;
case 3:
search(item, total);
case 4:
return;
}
}
}
void input_item(struct as item[], int total)
{
printf(제품명: );
gets(item[total].product);
printf(날짜: );
scanf(%d, &item[total].date);
fflush(stdin);
printf(고객명: );
gets(item[total].customer);
printf(전화번호: );
gets(item[total].tel);
}
void output_items(struct as item[], int total)
{
int i;
for (i = 0; i = total; i++) {
printf(\nas #%d\n, i);
printf(제품명: %s\n, item[i].product);
printf(고객명: %s\n, item[i].customer);
printf(전화번호: %s\n, item[i].tel);
printf(날짜: %d\n, item[i].date);
}
}
void search(struct as item[],int total){
int i;
int check=0;
char searchname[10];
printf(찾을 고객명?);
gets(searchname);
fflush(stdin);
for(i = 0; i = total; i++){
if(strcmp(item[i].customer,searchname)==0){
check =1 ;
printf(\nas #%d\n, i);
printf(제품명: %s\n, item[i].product);
printf(고객명: %s\n, item[i].customer);
printf(전화번호: %s\n, item[i].tel);
printf(날짜: %d\n, item[i].date);
}
}
if(check==0)
printf(찾는 고객명이 없습니다.\n);
}
-
나오
아 정말이네요ㅋㅋㅋㅋ
그걸 못봤다니 헛웃음이 나오네요 감사합니다. -
은아
case3 에 break 문이 없습니다.
check로 검색유무를 검사하셔도 되고
검색된 조건이 있으면 break로 탈출 후 루프 제어변수와 total값을 비교해서 하셔도 됩니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692401 | 유닉스안에서 C언어를 이용한 명함 만들기 입니다; 이해안가는 부분이있네요 | 2gether | 2025-04-22 |
2692374 | 고수님들 댓글 마니부탁해요!!! (2) | 엄지 | 2025-04-22 |
2692343 | scnaf에 자꾸 선언을 참조하라는데;; (8) | 도래 | 2025-04-22 |
2692282 | 도스상에서 생성된 exe파일에 press~ 뜨게 하기 (4) | 회사원 | 2025-04-21 |
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |