gpt4 book ai didi

c - 程序跳过输入并无故崩溃

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

<分区>

好的,所以如果修复它并且我可以展示它(我使用 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");
}
}

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