| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 656 人关注过本帖
标题:求助,关于结构体
只看楼主 加入收藏
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:0 
10楼威武,果然好用,可是为什么把函数的声明部分放到外面就能通过呢?????

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2012-11-10 20:05
lxq6966892
Rank: 2
等 级:论坛游民
帖 子:16
专家分:15
注 册:2012-10-4
收藏
得分:0 
这是我改的,运行没问题。

#include<stdio.h>
struct Student
{
    int num;
    char name[10];   /*定义数据结构并定义该结构的有3个元素的数组*/
    int score[3];
};struct Student stu[3];
main()
{   struct Student *p; /*定义一个结构体的指针*/
    struct Student* input(void);/*声明一个返回结构体指针的无参input函数*/
   void  output(struct Student*);/*声明一个以结构体指针为参数的无返回output函数*/
    p=input();   /*指针p接收input返回值*/
    output(p);  /*指针p作为函数output的参数*/
    return 0;
}
struct Student* input(void)
{

    int i,j;
    for(i=0;i<3;i++)
    {   printf("input the %d of 3",i+1);
        printf("\nnum:");
        scanf("%d",&stu[i].num);
        printf("\nname:");
        scanf("%s",stu[i].name);
        for(j=0;j<3;j++)
        {
            printf("\nscore%d:",j+1);
            scanf("%d",&stu[i].score[j]);

        }   /*此处循环输入结构体数组的内容*/
    }
    return(stu);/*返回结构体指针*/
}
void output(struct Student *stu)
{
    int i,j;
    printf("num         name         score1      score2     score3");
    for(i=0;i<3;i++)
    {
        printf("%d%s",stu[i].num,stu[i].name);
        for(j=0;j<3;j++)
        {                   /*输出*/
            printf("%d",stu[i].score[j]);
            printf("\n");
        }
    }
}
2012-11-11 10:38
快速回复:求助,关于结构体
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013023 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved