| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 12416 人关注过本帖
标题:C 提示初始值设定项值太多 是什么意思?
只看楼主 加入收藏
PolinL
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-2-12
收藏
 问题点数:0 回复次数:4 
C 提示初始值设定项值太多 是什么意思?
代码如下
#include <stdio.h>
#define SLEN 40
#define LIM 5
int main(void)
{   
    const char *mytalents[LIM] = {
        "Adding numbers swiftly",
        "Multiplying accurately", "Stashing data",
        "Following instructions to the letter",
        "Understanding the C language"
    };
    char yourtalents[SLEN] = {
        "Walking in a staight line",
        "Sleeping", "Watching television",
        "Mailing letters", "Reading eamai"
    };

    system("pause");
    return 0;
}

14行sleeping部分被画红,提示初始值设定项值太多,是什么情况?
求大神解答,谢谢
搜索更多相关主题的帖子: 提示 初始值 设定 char the 
2018-03-04 22:52
PolinL
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2018-2-12
收藏
得分:0 
#include <stdio.h>
#define SLEN 40
#define LIM 5
int main(void)
{   
    const char *mytalents[LIM] = {
        "Adding numbers swiftly",
        "Multiplying accurately", "Stashing data",
        "Following instructions to the letter",
        "Understanding the C language"
    };
    char yourtalents[LIM][SLEN] = {
        "Walking in a staight line",
        "Sleeping", "Watching television",
        "Mailing letters", "Reading eamai"
    };
    int i;

    puts("Let's compare talents.");
    printf("%-36s  %-25s\n", "My Talents", "Your Talents");
    for (i = 0; i < LIM; i++)
        printf("%-36s  %-25s\n", mytalents[i], yourtalents[i]);
    printf("\nsizeof mytalents: %zd, sizeof yourtalents: %zd\n", sizeof(mytalents), sizeof(yourtalents));

    system("pause");
    return 0;
}
发现自己错误的地方了,修改红色部分后就正常运行了。
2018-03-04 23:06
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10540
专家分:42927
注 册:2014-5-20
收藏
得分:0 
char yourtalents[SLEN] 这是数组
char yourtalents[SLEN] = "Walking in a staight line"; 这样就可以。
2018-03-04 23:09
yuandefeng
Rank: 4
等 级:业余侠客
威 望:3
帖 子:51
专家分:216
注 册:2017-11-28
收藏
得分:0 
多个字符串  相当于二维数组。
2018-03-09 21:36
ambi34t
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2023-3-22
收藏
得分:0 
#include <stdio.h>
#define SLEN 40
#define LIM 5
int main(void)
{
    const char* mytalents[LIM] = {
        "Adding numbers swiftly",
        "Multiplying accurately", "Stashing data",
        "Following instructions to the letter",
        "Understanding the C language"
    };
    char *yourtalent[SLEN] = {
        "Walking in a staight line",
        "Sleeping", "Watching television",
        "Mailing letters", "Reading eamai"
    };

    system("pause");
    return 0;
}加一个指针就好了(加一个红色的星号)
2023-03-22 21:05
快速回复:C 提示初始值设定项值太多 是什么意思?
数据加载中...
 
   



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

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