鱼C论坛

 找回密码
 立即注册
查看: 3527|回复: 3

有没有大神,解决一个简单结构体问题

[复制链接]
发表于 2018-4-29 11:52:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
新手刚学到结构体,用VC6.0写了个简单小程序,记录学生基本信息。debug不出问题但运行出错,大神帮忙看一下好不好啊!

#include<stdio.h>

void main()
{
    struct date
    {
        int month;
        int day;
        int year;
    };

    struct student
    {
        int num;
        char name;
        char sex;
        struct date birthday;
        double score;
    }boy1, boy2;

    printf("please input number: ");
    scanf("%d", &boy1.num);
    printf("please input name: ");
    scanf("%s", &boy1.name);
    printf("please input sex: ");
    scanf("%s", &boy1.sex);
    printf("please input score: ");
    scanf("%lf", &boy1.score);
    printf("please input birthday(MM): ");
    scanf("%d", &boy1.birthday.month);
    printf("please input birthday(DD): ");
    scanf("%d", &boy1.birthday.day);
    printf("please input birthday(YY): ");
    scanf("%d", &boy1.birthday.year);

    boy2 = boy1;

    printf("Student Number = %d\nStudent Name = %s\nStudent Sex = %s\n", boy1.num, boy1.name, boy1.sex);
    printf("Student Birthday = %d-%d-%d\nStudent Score = %lf\n\n", boy1.birthday.year, boy1.birthday.month, boy1.birthday.day, boy1.score);
    printf("Student Number = %d\nStudent Name = %s\nStudent Sex = %s\n", boy2.num, boy2.name, boy2.sex);
    printf("Student Birthday = %d-%d-%d\nStudent Score = %lf\n\n", boy2.birthday.year, boy2.birthday.month, boy2.birthday.day, boy2.score);

}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-4-29 12:39:58 | 显示全部楼层
struct student
{
    int num;
    char name[20];
    char sex[6];

    struct date birthday;
    double score;
}boy1, boy2;
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-4-29 13:02:03 | 显示全部楼层
ba21 发表于 2018-4-29 12:39
struct student
{
    int num;

谢谢你,又是你帮我解答的。
这里想多问一句,是不是字符串必须赋值给数组,不能直接赋值?(基础学得不太好)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-4-29 14:12:17 | 显示全部楼层
超级熊宝宝 发表于 2018-4-29 13:02
谢谢你,又是你帮我解答的。
这里想多问一句,是不是字符串必须赋值给数组,不能直接赋值?(基础学得不 ...

c没有字符串的概论,只有char
字符串用char数组表示
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-1 21:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表