473,461 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

suggest me the way in which the array of structures

62
Hi in C
can any one suggest me the way in which the array of structures
needs to be declared , with out mentioning the size of the array.
eg like

static struct rwtable { /* reserved word table */
char * rw_name; /* representation */
int rw_yylex; /* yylex() value */
} rwtable[1000];

And also suggest me the way in which I can initaise this structure

Thanks & Regards

srikar
Oct 11 '06 #1
6 1977
srikar
62
Hi all when i am using this declaration in my code

static struct rwtable { /* reserved word table */
char * rw_name; /* representation */
int rw_yylex; /* yylex() value */
} rwtable[]={
"", 0
};

I am getting warning like

warning: aggregate has a partly bracketed initializer

please help me to resolve this warning
Oct 11 '06 #2
arne
315 Expert 100+
Hi all when i am using this declaration in my code

static struct rwtable { /* reserved word table */
char * rw_name; /* representation */
int rw_yylex; /* yylex() value */
} rwtable[]={
"", 0
};

I am getting warning like

warning: aggregate has a partly bracketed initializer

please help me to resolve this warning
Put curly braces around your initial values: {"",0}.
Oct 11 '06 #3
Banfa
9,065 Expert Mod 8TB
If you add a well formed initialiser the is no need to give the array size. The compiler will size the array from the initialiser

Expand|Select|Wrap|Line Numbers
  1. static struct rwtable { /* reserved word table */
  2. char * rw_name; /* representation */
  3. int rw_yylex; /* yylex() value */
  4. } rwtable[] = {
  5.   {"FOR", 0},
  6.   {"EACH", 1},
  7.   {"UNTIL", 2}
  8. };
  9.  
The array will automatically have a size of 3.
Oct 11 '06 #4
Banfa
9,065 Expert Mod 8TB
Please don't double post.
Oct 11 '06 #5
srikar
62
Hai Banfa Thanks for the reply.

Actually, I need to initialise all the values with zero.
I donot know the size of array.
I want to initialise all the structures with zero values.

please suggest in this way
Oct 11 '06 #6
Banfa
9,065 Expert Mod 8TB
If you do not know the size of the array that suggests that you need to have some sort of dynamic array, in which case knowing how to initialise the array is irrelivent since all dynamic arrays work off pointers and memory allocation.

If you did have the structure given in the OP then you could use

Expand|Select|Wrap|Line Numbers
  1. static struct rwtable { /* reserved word table */
  2.   char * rw_name; /* representation */
  3.   int rw_yylex; /* yylex() value */
  4. } rwtable[1000] = {0};
  5.  
To initialise all members to 0.
Oct 11 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
8
by: ulyses | last post by:
I'm trying to put pointer to flexible array of structures in other structure. I want to have pointer to array of pixels in screen structure. Here is mine code, but I think it isn't quite all right:...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Sam | last post by:
Hello I have a structure called Company. struct Company { char *employee; char *employee_address; }; I want to build an array of this structure but the number of employees will change...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
44
by: svata | last post by:
Hello, I wonder how to resize such array of structures using realloc()? #include <stdio.h> #include <stdlib.h> #define FIRST 7 typedef struct { char *name;
17
by: Ben Bacarisse | last post by:
candide <toto@free.frwrites: These two statements are very different. The first one is just wrong and I am pretty sure you did not mean to suggest that. There is no object in C that is the...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.