【新手求助】C语言的问题,麻烦大家帮我看看错在哪里了,谢谢!
这是题目原文:这是错误信息:
代码如下:
程序代码:/* 14.5 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define CSIZE 4
struct name
{
char * first;
char * last;
};
struct student
{
struct name name;
double grade[3];
double average;
};
int main (void)
{
struct student student[CSIZE];
int count; /* 结构体计数 */
int count_ch; /* 字符计数 */
int count_grd; /* 分数计数 */
char ch;
double sum[CSIZE];
for (count = 0; count < CSIZE; count++)
{
count_ch = 0;
sum[CSIZE] = 0;
printf ("Please enter the first name:");
while (ch = getchar () && isalpha (ch))
{
ungetc (ch, stdin);
count_ch++;
}
student[count].name.first = (char *) calloc (count_ch + 1, sizeof (char));
gets (student[count].name.first); /* 从输入流中获取字符 */
fflush (stdin);
count_ch = 0;
printf ("Please enter the last name:");
while (ch = getchar () && isalpha (ch))
{
ungetc (ch, stdin);
count_ch++;
}
student[count].name.last = (char *) calloc (count_ch + 1, sizeof (char));
gets (student[count].name.last); /* 从输入流中获取字符 */
fflush (stdin);
for (count_grd = 0; count_grd < 3; count_grd++)
{
printf ("Please enter the %dth grade:", count_grd + 1);
scanf ("%lf", student[count].grade[count_grd]);
sum[CSIZE] += student[count].grade[count_grd];
}
student[count].average = sum[CSIZE] / 3;
}
for (count = 0; count < CSIZE; count++)
{
printf ("Name: ");
puts (student[count].name.first);
putchar (' ');
puts (student[count].name.last);
putchar ('\n');
printf ("printf Grade: ");
for (count_grd = 0; count_grd < 3; count_grd++)
printf ("%g ", student[count].grade[count_grd]);
putchar ('\n');
printf ("Avearage: %g\n\n", student[count].average);
}
printf ("The average of the whole class is %g\n", (sum[0] + sum[1] + sum[2]) / 3);
return 0;
}[ 本帖最后由 DarylL 于 2013-5-1 08:47 编辑 ]






