우리는 어떻게 구조체의 멤버를 검색하여 모든 멤버를 출력 할 수 있습니까?
- 에 사용자를 활성화 할 C의 특정 프로그램을 코딩했다 학생 종료
에 대한
#include<stdio.h>
typedef struct tag1{
int day, year, month;
}Date;
typedef struct tag2{
int number;
char name[50];
char course[30];
Date birthday;
}Record;
main(){
int choice, n, i=0;
Record student[200];
//printing of menu:
printf("Choose from the menu:\n");
printf(" [1] Add Student\n");
printf(" [2] Search Student\n");
printf(" [3] View All\n");
printf(" [4] Exit\n");
scanf("%d", &choice);
if((choice>=1)&&(choice<=4)){
if(choice==1){
printf("Enter student number:\n");
scanf("%d", &student[n].number);
printf("Enter the name of the student:\n");
scanf("%[^\n]", student[n].name);
printf("Enter month of birth:\n");
scanf("%d", &student[n].birthday.month);
printf("Enter day of birth:\n");
scanf("%d", &student[n].birthday.day);
printf("Enter year of birth:\n");
scanf("%d", &student[n].birthday.year);
printf("Enter course:\n");
scanf("%[^\n]", student[n].course);
n++;
}
if(choice==2){
while(i<n){
printf("%d\n", student[n].number);
printf("%s", student[n].name);
printf("%d/%d/%d", student[n].birthday.month, student[n].birthday.day,student[n].birthday.year);
printf("%s", student[n].course);
i++;
}
}
}
}
나는 학생을 어떻게 검색 할 것인지 잘 모르기 때문에 반쯤 지났습니다. 제 코드 개선을위한 제안이 있으시길 바랍니다.
segfault는 어디에서 발생합니까? 당신은 디버거에서 찾을 수 있습니까? – Floris