| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1029 人关注过本帖
标题:检查无错误,但是运行的时候就会出错,大家帮忙看看
只看楼主 加入收藏
WolfmanThing
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-1-15
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:7 
检查无错误,但是运行的时候就会出错,大家帮忙看看
#include<stdio.h>
#define N 5
struct stu
{
    int numb;
    char nam[20];
    double sco[3];
};
void main()
{
    struct stu st[N];
    int i,j,count=0;
    for(i=0;i<N;i++)
    {
        scanf("%d",st[i].numb);
        scanf("%s",st[i].nam);
        for(j=0;j<3;j++)
            scanf("%f",st[i].sco[j]);
    }
    for(i=0;i<N;i++)
        printf("%12d%8s%5f%5f%5f",st[i].numb,st[i].nam,st[i].sco[0],st[i].sco[1],st[i].sco[2]);
}
搜索更多相关主题的帖子: include double count 
2016-01-15 16:22
WolfmanThing
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-1-15
收藏
得分:0 
来个人~~~帮帮~
2016-01-15 16:29
wengbin
Rank: 10Rank: 10Rank: 10
来 自:陕西西安
等 级:贵宾
威 望:19
帖 子:370
专家分:1846
注 册:2015-5-8
收藏
得分:20 
程序代码:
#include<stdio.h>
#define N 5
typedef struct stu
{
    int numb;
    char nam[20];
    double sco[3];
}stu;
int main()
{
    struct stu st[N];
    int i;
    for(i=0;i<N;i++)
    {
        printf("enter the number of struct #%d: ",i+1);
        scanf("%d",&st[i].numb);
        printf("enter the nam of struct #%d: ",i+1);
        scanf("%s",&st[i].nam);
        printf("enter the sco of struct #%d(3 numbers): ",i+1);
        scanf("%lf %lf %lf",&st[i].sco[0],&st[i].sco[1],&st[i].sco[2]);
    }
    for(i=0;i<N;i++)
        printf("%12d%8s%5f%5f%5f",st[i].numb,st[i].nam,st[i].sco[0],st[i].sco[1],st[i].sco[2]);
    return 0;
}//结构体类似于一般变量,读入时要取址读,没有&算符,一直没有读入,当第地次输入完了,数据仍在缓冲区吧可能,所以无法继续下一步
收到的鲜花
  • WolfmanThing2016-01-15 16:50 送鲜花  3朵   附言:我很赞同
2016-01-15 16:41
wengbin
Rank: 10Rank: 10Rank: 10
来 自:陕西西安
等 级:贵宾
威 望:19
帖 子:370
专家分:1846
注 册:2015-5-8
收藏
得分:0 
一看信息,又是一新人,提醒一声,看到我的解决办法后除了说感谢,还要早点结贴给我分呀
2016-01-15 16:43
WolfmanThing
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-1-15
收藏
得分:0 
回复 3楼 wengbin
嗯,今年大一才学的 C 语言。
谢谢!
2016-01-15 16:48
wengbin
Rank: 10Rank: 10Rank: 10
来 自:陕西西安
等 级:贵宾
威 望:19
帖 子:370
专家分:1846
注 册:2015-5-8
收藏
得分:0 
你的打印部分太难看了,都不换下行,怎么看?用下面这个
程序代码:
#include<stdio.h>
#define N 1
typedef struct stu
{
    int numb;
    char nam[20];
    double sco[3];
}stu;
int main()
{
    struct stu st[N];
    int i;
    for(i=0;i<N;i++)
    {
        printf("enter the number of struct #%d: ",i+1);
        scanf("%d",&st[i].numb);
        printf("enter the nam of struct #%d: ",i+1);
        scanf("%s",&st[i].nam);
        printf("enter the sco of struct #%d(3 numbers): ",i+1);
        scanf("%lf %lf %lf",&st[i].sco[0],&st[i].sco[1],&st[i].sco[2]);
    }
    printf("the numb\tthe name\t\tthe sco\t\t\t\n");
    for(i=0;i<N;i++)
        printf("%2d\t\t%8s\t%5f\t%5f\t%5f\n",st[i].numb,st[i].nam,st[i].sco[0],st[i].sco[1],st[i].sco[2]);
    return 0;
}
2016-01-15 16:54
wengbin
Rank: 10Rank: 10Rank: 10
来 自:陕西西安
等 级:贵宾
威 望:19
帖 子:370
专家分:1846
注 册:2015-5-8
收藏
得分:0 
为了调试方便,N被改成1了,自己调整呀
2016-01-15 16:55
z450558237
Rank: 2
等 级:论坛游民
帖 子:48
专家分:11
注 册:2014-10-21
收藏
得分:0 
你scanf输入数字都不加取址符&的啊
2016-01-16 13:35
快速回复:检查无错误,但是运行的时候就会出错,大家帮忙看看
数据加载中...
 
   



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

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