初始化结构 [英] initialize structs

查看:78
本文介绍了初始化结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我对结构有疑问..我必须关注:


typedef struct STATS

{

int src;

int dest;

int total;

int drop;

} STATS;


然后,以下内容:


STATS e_STATS [10];


我希望我的e_STATS [10]初始化为0 ...但是,我尝试了几种方式

我无法使其工作..


tnx,

费尔南多

Hi,

I have a doubt regarding structus.. I have to following:

typedef struct STATS
{
int src;
int dest;
int total;
int drop;
} STATS;

And then, the following:

STATS e_STATS[10];

I want my e_STATS[10] initialize to 0... however, i tried several ways
and i cannot make it work..

tnx,
Fernando

推荐答案

搞定了.. e_STATS是一个int *。 ..所以,一种方法就是做''memset''...

对不起,我没想过......


tnx,

Fernando

Got it.. e_STATS is an int *... so, the one way is to do ''memset''...
sorry, i didnt think it through..

tnx,
Fernando


FBM写道:


我有关于structus的疑问..我必须遵循:

typedef struct STATS
int src;
int dest;
int total;
int drop;
} STATS ;

然后,以下内容:

STATS e_STATS [10];

我希望我的e_STATS [10]初始化为0 ...然而,我尝试了几种方式
我无法使其工作..
Hi,

I have a doubt regarding structus.. I have to following:

typedef struct STATS
{
int src;
int dest;
int total;
int drop;
} STATS;

And then, the following:

STATS e_STATS[10];

I want my e_STATS[10] initialize to 0... however, i tried several ways
and i cannot make it work..




将声明更改为


STATS e_STATS [10] = {0};


,它将被初始化为0.


/ Michael



Change the declaration to

STATS e_STATS[10] = { 0 };

and it will be initialized to 0.

/Michael


谢谢..它正在工作,但我得到了这个令人讨厌的警告..


STATS mySTATS [10] = {0};


gcc -DMEMWATCH -O0 -g3 -Wall -c -fmessage-length = 0 -omain.o ../main.c

... / main .c:在函数''main''中:

... / main.c:44:警告:初始化程序周围缺少大括号

... / main.c :44:警告:(接近初始化''mySTATS [0]'')

完成建筑物:../ main.c


任何想法为什么?


tnx,

Fernando

Thanks.. it''s working, but i get this nasty warning..

STATS mySTATS[10] = { 0 };

gcc -DMEMWATCH -O0 -g3 -Wall -c -fmessage-length=0 -omain.o ../main.c
.../main.c: In function ''main'':
.../main.c:44: warning: missing braces around initializer
.../main.c:44: warning: (near initialization for ''mySTATS[0]'')
Finished building: ../main.c

Any idea why?

tnx,
Fernando


这篇关于初始化结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆