| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 359 人关注过本帖
标题:大家帮忙看看结构体内整型数组scanf赋值错误问题
只看楼主 加入收藏
oufala
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-11-16
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:1 
大家帮忙看看结构体内整型数组scanf赋值错误问题
这是代码的前部分:
int main()
{
    struct Student stu[3] = { { 11, 10001, "Zhang", 99.5, 88.5, 89.5 }, { 12, 10002, "Yang", 77.9, 56.5, 87.5 }, { 11, 10003, "Liang", 92.5, 99.0, 60.5 } };
    struct Student temp;
    const int n = 3;
    int j, k, i;
    struct Student stu1;
    for (i = 0; i < n - 1; i++)
    {
        k = i;
        for (j = i + 1; j < n; j++)
        if (stu[j].banji < stu[k].banji)
        {
            k = j;
            temp = stu[k];
            stu[k] = stu[i];
            stu[i] = temp;
        }
    }
    scanf("%d %d %s %f %f %f", &stu1.id, &stu1.banji, stu1.name, &stu1.score[0], &stu1.score[1], &stu1.score[2]);
输入10001 11 Zhang 55.0 56.0 57.0后stu1的score部分赋值错误:
-        score    0x0084f9f8 {-9.2559604829362779e+061, -9.2559604832355934e+061, -9.2559604835349090e+061}    double[3]
这是什么原因,初学者请多指教
2015-11-16 13:53
lzl123321
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:41
专家分:148
注 册:2015-10-15
收藏
得分:14 
以下是引用oufala在2015-11-16 13:53:57的发言:

这是代码的前部分:
int main()
{
    struct Student stu[3] = { { 11, 10001, "Zhang", 99.5, 88.5, 89.5 }, { 12, 10002, "Yang", 77.9, 56.5, 87.5 }, { 11, 10003, "Liang", 92.5, 99.0, 60.5 } };
    struct Student temp;
    const int n = 3;
    int j, k, i;
    struct Student stu1;
    for (i = 0; i < n - 1; i++)
    {
        k = i;
        for (j = i + 1; j < n; j++)
        if (stu[j].banji < stu[k].banji)
        {
            k = j;
            temp = stu[k];
            stu[k] = stu;
            stu = temp;
        }
    }
    scanf("%d %d %s %f %f %f", &stu1.id, &stu1.banji, stu1.name, &stu1.score[0], &stu1.score[1], &stu1.score[2]);
输入10001 11 Zhang 55.0 56.0 57.0后stu1的score部分赋值错误:
-        score    0x0084f9f8 {-9.2559604829362779e+061, -9.2559604832355934e+061, -9.2559604835349090e+061}    double[3]
这是什么原因,初学者请多指教




 &stu1.id, &stu1.banji, stu1.name, &stu1.score[0]
结构体你定义了么?没有定义结构体,内存都没有分配,怎么输入的数据,数据输入都有问题,怎么可能正常输出呢
我是新手,窃以为大神不愿意现身的首要原因是:你得先把代码写的规范清洁吧
然后您先把结构体相关的章节看一遍,看看结构体定义以及使用的规范操作,上来就爆结构体+数组套数组,大神宁愿多看几个例题也不愿意去理解你的代码啊,orZ!!!
2015-11-17 13:08
快速回复:大家帮忙看看结构体内整型数组scanf赋值错误问题
数据加载中...
 
   



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

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