在C中为结构设置值 [英] Set Value for structure in C

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

问题描述

大家好,

我在C中有一个结构,如下所示:

Hello ALL,

I have a structure in C as follow:

Static struct{
              int  aaa;
              char bbb;
              int  ccc;
              char ddd;
             }form[2];


我为其设置值如下:


and I set value for it as below:

form[0]={8,''a'',6,''b''};
form[1]={9,''s'',5,''v''};



那么我为表格设置的值是否正确?
我需要您的尽快答复!



So I set value for form is correct or not?
I need your answer as soon as possible!

thanks.

推荐答案

实际上您的代码不正确,但是我将留给您查看什么是从零开始的索引编制,您将了解什么是错误的.
Actually your code is not correct, but I will leave it to you to look up what zero-based indexing is and you will understand what is wrong.


除了索引错误之外,还有其他问题.
提议的初始化结构的方法只能在声明中使用,不能在之后使用.

这样就可以了:
Besides the indexing mistake, something else is wrong too.
The proposed method of initialising a structure can be used only in the declaration, not afterward.

So this would be fine:
static struct{
    int  aaa;
    char bbb;
    int  ccc;
    char ddd;
}form[2] = {8,''a'',6,''b'',9,''s'',5,''v''};



但是要稍后进行修改,您必须像这样进行操作:



But to modify it later, you would have to do it like this:

form[1].aaa =  9;
form[1].bbb = ''s'';
form[1].ccc =  5;
form[1].ddd = ''v'';


答案是否;如果您可以使用计算机和c编译器,则应自己弄清楚.
The answer is Yes No; If you have access to a computer and a c compiler, then you should figure this out yourself.


这篇关于在C中为结构设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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