标题:警告 c4047: ‘ initializing': ‘ char'与‘ char [2]'的间接级别不同
只看楼主
mm1746886443
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2019-11-2
结帖率:50%
 问题点数:0 回复次数:4 
警告 c4047: ‘ initializing': ‘ char'与‘ char [2]'的间接级别不同
#include<stdio.h>
struct stu
{
    int num;
    char *name;
    char sex;
    float score;
}
boy[5]={
    {101,"Li ping","M",45},
    {102,"Zhang ping","M"62.5},
    {103,"He fang ","F",92.5},
    {104,"Cheng ling","F",87},
    {105,"Wang ming","M",58},
};
main()
{
    int i,c=0;
    float ave,s=0;
    for(i=0;i<5;i++)
    {
        s+=boy[i].score;
        if(boy[i].score<60) c+=1;

    }
    printf("s=%f\n",s);
        ave=s/5;
    printf("average=%f\ncount=%d\n",ave,c);
}
搜索更多相关主题的帖子: score 级别 不同 char 警告 
2019-12-12 21:01
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:0 
"M" 等改为 'M'
"M"62.5 之间也少了个逗号吧
2019-12-12 21:48
mm1746886443
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2019-11-2
得分:0 
回复 2楼 rjsp
一针见血我sex前面加个*可以吗
2019-12-12 22:45
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:0 
以下是引用mm1746886443在2019-12-12 22:45:13的发言:

一针见血我sex前面加个*可以吗

你是指 *sex 还是 *"M"; 前者错误,后者虽然怪异但可以

另外,你应该规规矩矩写代码
程序代码:
#include <stdio.h>

struct stu
{
    int num;
    char name[50];
    char sex;
    float score;
};

int main( void )
{
    struct stu boy[5] = { {101, "Li ping",    'M', 45.0f }
                        , {102, "Zhang ping", 'M', 62.5f }
                        , {103, "He fang",    'F', 92.5f }
                        , {104, "Cheng ling", 'F', 87.0f }
                        , {105, "Wang ming",  'M', 58.0f } };

    float sum = 0;
    unsigned failures = 0;
    const size_t count = sizeof(boy)/sizeof(*boy);
    for( size_t i=0; i!=count; ++i )
    {
        sum += boy[i].score;
        if( boy[i].score < 60 )
            ++failures;
    }

    printf( "sum = %.1f\n", sum );
    printf( "average = %.2f\n", sum/count );
    printf( "Number of failures = %u\n", failures );
}

2019-12-13 08:40
mm1746886443
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2019-11-2
得分:0 
回复 4楼 rjsp
刚刚起步啥都不懂
2019-12-13 16:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-498359-1-1.html




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

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