[c]1.구조체에서 gets함수로 문자열 입력이 안됩니다. 2. 한글문자열 입력이 안됩니다.
조회수 772회
c 공부중에 원인을 못 찾아 도움을 구합니다 ㅠㅠ
1. gets() 문자열 입력이 안됩니다.
#include<stdio.h>
struct bookstore_warehousing{
char name[30]; //이름
int price; //가격
int isbn; //넘버
int amount; //수량
};
void main(){
int book_total;
printf("===서점 입고 관리 시스템===\n등록할 책 종류 수를 입력하시오.\n");
scanf("%d", &book_total);
struct bookstore_warehousing warehousing[book_total];
for (int num = 0; num < book_total; num++){
printf("%d번째 서적\n",num+1);
printf("제목 : ");
gets(warehousing[num].name);
printf("가격 : ");
scanf("%d", &warehousing[num].price);
printf("ISBN : ");
scanf("%d", &warehousing[num].isbn);
printf("수량 : ");
scanf("%d", &warehousing[num].amount);
}
printf("===입고된 서적===\n번호\t\t제목\t\t가격\t\tISBN\t\t수량\n");
for (int a = 0; a < book_total; a++){
printf("%d\t\t%s\t\t%d\t\t%d\t\t%d\n", a+1, warehousing[a].name, warehousing[a].price, warehousing[a].isbn, warehousing[a].amount);
}
}
2.영어로 입력후 출력이 정상적으로 되지만 한글은 입력 후 출력이 안됩니다.
#include<stdio.h>
struct student_info{
char name[30];
int sex; //female=0 male=1
int age;
};
void main(){
int student_total;
printf("입력할 학생수는?\n");
scanf("%d", &student_total);
struct student_info student[student_total];
//입력
for (int num = 0; num < student_total; num++){
printf("=== %d번째 학생 입력 ===\n", num+1);
printf("이름 : ");
scanf("%s", student[num].name);
printf("성별(남성은 0, 여성은 1) : ");
scanf("%d", &student[num].sex);
printf("나이 : ");
scanf("%d", &student[num].age);
}
//출력
for (int num = 0; num < student_total; num++){
printf("=== %d번째 학생 정보 ===\n", num+1);
for (int entry = 0; entry < 3; entry++){
switch (entry){
case 0:
printf("이름 : %s\n", student[num].name);
break;
case 1:
printf("성별 : ");
if(student[num].sex == 0){
printf("남자\n");
}
else{
printf("여자\n");
}
break;
case 2:
printf("나이 : %d\n", student[num].age);
break;
}
}
}
}
댓글 입력