qq_43257669 2018-12-14 16:16 采纳率: 0%
浏览 590

为什么用指针输出不了

#include
#define N 20
struct Student
{
int num;
char name[10];
int computer,math,english;
double average;
};
struct Student stu[N];
int main()
{
struct Student update_score(struct Student *p,int n,int score);
int i,n;
printf("please enter the number of students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("No.%d:",i+1);
scanf("%d %s %d %d %d",&stu[i].num,stu[i].name,&stu[i].computer,&stu[i].math,&stu[i].english);
stu[i].average=(stu[i].computer+stu[i].math+stu[i].english)/3.0;
}

printf("the array is:\n");
for(i=0;i<n;i++)
    printf("%d %s %d %d %d %.2lf\n",stu[i].num,stu[i].name,stu[i].computer,stu[i].math,stu[i].english,stu[i].average);

int m,f,s;
printf("please input the number of the student that you want to update:\n");
scanf("%d",&m);
printf("please input the subject(1:computer,2:math,3:english) and the new score:\n");
scanf("%d,%d",&f,&s);

struct Student *p=&stu[m];
update_score(p,f,s);
printf("the new data is:\n");
printf("%d %s %d %d %d %.2lf\n",p->num,p->name,p->computer,p->math,p->english,p->average);
return 0;

}

struct Student update_score(struct Student *p,int n,int score)
{
if(n==1)
(*p).computer=score;
if(n==2)
(*p).math=score;
if(n==3)
(*p).english=score;
if(n!=1&&n!=2&&n!=3)
printf("error!\n");
(*p).average=((*p).computer+(*p).math+(*p).english)/3.0;
return(*p);
}

只有修改后那个分数可以

  • 写回答

2条回答 默认 最新

  • threenewbee 2018-12-15 03:34
    关注

    如果问题得到解决,请点我回答左上角的采纳和向上的箭头,谢谢

    程序没有问题,可能是输入的问题,最后那个编号,是你数组下标(注意不能大于数量-1)不是输入的学号。然后科目和分数中间英文半角逗号分割
    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献