何が起こるかは、性別を入力する時間に達すると、性別検索機能中に発生します。入力をスキップし、理由を示さずにクラッシュします。他の機能は、私が知る限り正常に動作します(エラーがそれらの1つが原因である可能性がある場合に備えて、ip utそこにある)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void getinfo (char* nam[],int ag[], char gender[], int count){
int y;
for(y = 0; y < count; y++){
nam[y] = malloc(50);
printf ("What is the student's name?\t");
scanf ("%s", nam[y]);
printf ("\nWhat is the students age?\t");
scanf ("%d", &ag[y]);
printf ("\nwhat is the students gender, Male/Female\t");
scanf (" %c", &gender[y]);
}
}
void findeldest (char* nam[],int ag[], char gender[], int count){
int largest = 0, y, eldest =0 ;
for(y = 0; y < count; y++){
if (ag[y] > eldest){
largest = ag[y];
eldest = y;
}
}
printf ("The eldest student is:\t %s", nam[eldest]);
printf ("\nGender:\t %c", gender[eldest]);
printf ("\nWith an age of:\t %d \n", ag[eldest]);
}
void gendersearch (char* nam[],int ag[], char gender[], int count){
int y;
char choice;
printf ("What gender would you like to see(male-m/female-f)?\n");
scanf ("%c", choice);
switch (choice){
case 'm' : printf ("The male students are as follows:\n");
case 'f' : printf ("The female students are as follows:\n");
default : printf ("please enter m for male or f for female!\n");
}
if (choice == 'm'){
for (y = 0 ; y < count; y++){
if (gender[y] == choice){
printf (nam[y]);
}
}
}else{
for (y = 0 ; y < count; y++){
if (gender[y] == choice){
printf (nam[y]);
}
}
}
}
int main (){
int amount, y;
printf("How many students are you admitting?\t");
scanf ("%d", &amount);
char *name[50];
int age[50];
char gender[50];
if (amount > 50){
printf("Too many students!");
}else{
getinfo(name, age, gender, amount);
findeldest(name, age, gender, amount);
}
gendersearch (name, age, gender, amount);
system("pause");}