確定,所以如果固定了起來,我這像樣的進入,如果是getinfo功能(使用codebloks BTW IM)之後的年齡它打印得到的性別,然後拿到其他的語句後面的語句人名稱,沒有讓我輸入(它似乎只是跳過這一部分),如果我選擇只繼續它將會崩潰計劃跳過輸入和崩潰沒有理由
#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");
}
}
您是否嘗試過使用調試器?使用一個會給你一個清楚的想法,爲什麼和這個程序崩潰。 – 2013-03-09 06:23:43