| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 508 人关注过本帖
标题:这里有什么问题吗??子程序
只看楼主 加入收藏
zxrd1989
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2011-5-11
结帖率:64.29%
收藏
已结贴  问题点数:10 回复次数:7 
这里有什么问题吗??子程序
  struct student
        {
            int num;
            char *name;
            char sex;
            char *major;
            int num;
        }boy[5]={{1,"郑银祥","男","计科",21},
                 {2,"周翔","男","计科",19},
        {3,"大明星","男","软工",20},
        {4,"小广东","男","计科",20},
        {5,"范欣晨","男","计科",20},
        {6,"宫成","男","计科",20}};
        
        
        struct student *ps;
        printf("床号\t姓名\t性别\t专业\t年龄\t\n");
        for(ps=boy;ps<boy+6;ps++)
            printf"%d\t%s\t%s\t%s\t%d\n",ps->num,ps->name,ps->sex,ps->major,ps->num);
搜索更多相关主题的帖子: 子程序 大明星 广东 姓名 欣晨 
2011-05-27 18:49
lz1091914999
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:四川
等 级:贵宾
威 望:37
帖 子:2011
专家分:5959
注 册:2010-11-1
收藏
得分:2 
struct student
        {
            int num;
            char *name;
            char sex;
            char *major;
            int num;
        }
name 和 major字段希望你能用数组,因为你很有可能要修改它。

My life is brilliant
2011-05-27 19:00
Toomj
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:257
专家分:1826
注 册:2011-5-17
收藏
得分:2 
struct student
        {
            int num;
            char *name;
            char sex;
            char *major;
            int age;
        }boy[6]={{1,"郑银祥",'M',"计科",21},
                 {2,"周翔",'M',"计科",19},
        {3,"大明星",'M',"软工",20},
        {4,"小广东",'M',"计科",20},
        {5,"范欣晨",'M',"计科",20},
        {6,"宫成",'M',"计科",20}};
            
        struct student *ps;
        printf("床号\t姓名\t性别\t专业\t年龄\t\n");
        for(ps=boy;ps<boy+6;ps++)
        printf("%d\t%s\t%c\t%s\t%d\n",ps->num,ps->name,ps->sex,ps->major,ps->age);
2011-05-27 19:01
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:2 
同意二楼

                                         
===========深入<----------------->浅出============
2011-05-27 19:05
xy19900513
Rank: 1
等 级:新手上路
帖 子:11
专家分:9
注 册:2011-4-22
收藏
得分:2 
回复 楼主 zxrd1989
图片附件: 游客没有浏览图片的权限,请 登录注册
额。。。楼主里面好多错误,,,人数和数组就不对,,自己看一下修改的吧,“男”是字符串不是字符。
程序代码:
#include<stdio.h>

void main()
{
     struct student
         {
             int num;
             char name[10];
             char sex[4];
             char major[10];
             int number;
         }boy[5]={{1,"郑银祥","","计科",21},
                  {2,"周翔","","计科",19},
         {3,"大明星","","软工",20},
         {4,"小广东","","计科",20},
         {5,"范欣晨","","计科",20}};
         
         
         struct student *ps;
         printf("床号\t姓名\t性别\t专业\t年龄\t\n");
         for(ps=boy;ps<boy+5;ps++)
             printf("%d\t%s\t%s\t%s\t%d\n",ps->num,ps->name,ps->sex,ps->major,ps->number); 
}
2011-05-27 19:06
zxrd1989
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2011-5-11
收藏
得分:0 
惭愧,这些还没讲,自己看书学的点
2011-05-27 19:11
Qingtian_2
Rank: 2
来 自:天津
等 级:论坛游民
帖 子:50
专家分:96
注 册:2011-3-9
收藏
得分:2 
结构里的sex元素是字符变量(按你定义的),而却赋了字符串初值……
2011-05-27 19:11
zxrd1989
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2011-5-11
收藏
得分:0 
回复 3楼 Toomj
为什么要把要用"M"才行呢?
2011-05-27 19:15
快速回复:这里有什么问题吗??子程序
数据加载中...
 
   



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

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