정말 간단한 코딩을 만들고 오류가 없지만 실행하면 '나이'쪽에 입력을 넣을 수 없습니다.배열에서 int를 사용하는 방법?
#include <stdio.h>
#include <conio.h>
struct baby
{
char name[2][30];
char sex[2][7];
char birthday[2][12];
};
struct parents
{
char nama[2][30];
int age[2];
};
struct momdad
{
struct parents father;
struct parents mother;
};
struct momdad info;
struct baby newborn;
int main()
{
int i;
for(i=0;i<2;i++)
{
printf("\nEnter baby's name %d: ",i+1);
gets(newborn.name[i]);
printf("Enter baby's sex %d (Female/Male): ",i+1);
gets(newborn.sex[i]);
printf("Enter baby's birthday %d (dd/mm/yyyy): ",i+1);
gets(newborn.birthday[i]);
printf("Enter father's name %d: ",i+1);
gets(info.father.nama[i]);
printf("Enter father's age %d: ",i+1);
gets(info.father.age[i]);
printf("Enter mother's name %d: ",i+1);
gets(info.mother.nama[i]);
printf("Enter mother's age %d: ",i+1);
gets(info.mother.age[i]);
}
printf("\n\n\tNEW BORN BABY IN KUANTAN HOSPITAL");
printf("\n\n===============================================");
for(i=0;i<2;i++)
{
printf("\n\nBaby name: %s",newborn.name[i]);
printf("\nSex: %s",newborn.sex[i]);
printf("\nBirthday: %s",newborn.birthday[i]);
printf("\n\nFather name: %s",info.father.nama[i]);
printf("\nFather age: %s",info.father.age[i]);
printf("\n\nMother name: %s",info.mother.nama[i]);
printf("\nMother age: %s",info.mother.age[i]);
printf("\n\n----------------------------------------------");
}
getch();
}
이것은 내 선언이 잘못되었다고 생각하지만 어떻게 알지 못합니다.
int age[2];
및 입력이 여기에 여기
printf("Enter father's age %d: ",i+1);
gets(info.father.age[i]);
N에 넣어 될 것이다
printf("Enter mother's age %d: ",i+1);
gets(info.mother.age[i]);
내가 프로그래밍에 여전히 새로운 해요 죄송이 간단한 질문
'gets()'는 문자열이 아닌 정수를 읽는 데 사용됩니다. 'scanf()'를 보아라. 이것은 다른 타입을 읽는데 사용될 수있다. – Barmar
@Barmar 전에 scanf를 사용했지만 똑같은 일이 발생했습니다. ( –
@EricJablow 물론 남성과 여성의 두 남녀가 있습니다. 아기가 섹스를 하나만 가지고 있습니까? –