好的,所以如果修复它并且我可以展示它(我正在使用 codebloks btw),在 getinfo 函数中输入年龄后它会打印语句以获取性别,然后打印语句以获取其他人的姓名而不让我输入(它似乎跳过那部分),如果我选择继续它会崩溃
#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(30);
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, M/F:\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", ag[eldest]);
}
int main (){
int amount, y;
printf("How many students are you admitting?\t");
scanf ("%d", &amount);
if (amount > 50){
printf("Too many students!");
}else{
char *name[50];
int age[50];
char gender[50];
getinfo(name, age, gender, amount);
findeldest(name, age, gender, amount);
system("pause");
}
}