gpt4 book ai didi

查找最大年龄时代码崩溃(编辑)

转载 作者:太空宇宙 更新时间:2023-11-04 06:35:45 29 4
gpt4 key购买 nike

<分区>

好的,所以 iffixed 了它,我做了一些建议,我得到了同样的错误(顺便说一句,我正在使用 codebloks),它的错误只是在没有给出原因的情况下崩溃。我遇到了第二个错误。在输入年龄后的 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");
}
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com