473,378 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Nesting an array of strings inside a array of structures

This is wht i want to do

typedef struct _notificationdataformat_ {
char *m_OID;
char **m_OIDList;
f1 funcptr;
} NOTIFICATIONDATAFORMAT;

NOTIFICATIONFORMAT OIDLIST[] = {
{ "temp",{"temp1","temp11"},&func1},
{ "temp2",{"temp21","temp22","temp23"},&func2}
};

The compiler does not compile this code and comes up with the error
initializer for scalar variable requires one element

Is there way around this or wht i m doing is completely wrong

Apr 10 '06 #1
4 1935

Amit Limaye wrote:
This is wht i want to do

typedef struct _notificationdataformat_ {
char *m_OID;
char **m_OIDList;
f1 funcptr;
} NOTIFICATIONDATAFORMAT;

NOTIFICATIONFORMAT OIDLIST[] = {
{ "temp",{"temp1","temp11"},&func1},
{ "temp2",{"temp21","temp22","temp23"},&func2}
};


You can't do this. The reason is how arrays work. {"xx", "xx", "xx"}
is an array of char pointers. It is reall a char *[], not a char **.
A char ** can point at a char *[] but there is an important distinction
here.

Arrays take space based on how many elements are in them. A pointer
takes a certain set amount of space, always (different types can have
different size pointers but a pointer to a type will always be the same
size).

To be able to initialize the above you would need the char ** to be
turned into a char *[]. This is not valid because then your structure
has no defined shape and size...just won't work.

You could create an upper bound to your array but upper bounds are
known to break. This would work because an array initialized with
fewer elements than it has available fills with 0. Not a very good
design though.

So you could turn char ** into char *[100] for example (I believe that
would compile) but again, I am not recommending this code...it just
answers your question.

Apr 10 '06 #2
Thanks noah,
I m trying to autogenerated code from a SNMP MIB
which has this structure and each element in the array was the
information structure of each message. I was just trying to avoid
writing a specific handler for each message which it seems is not
possible unless and until i know a max element number before hand.
Think i will revert back to each message represented by a structure.
But this approach leaves me with needing to write a function for each
message i expect

-SIGTERM
amit

Apr 10 '06 #3

Amit Limaye wrote:
Thanks noah,
I m trying to autogenerated code from a SNMP MIB
which has this structure and each element in the array was the
information structure of each message. I was just trying to avoid
writing a specific handler for each message which it seems is not
possible unless and until i know a max element number before hand.
Think i will revert back to each message represented by a structure.
But this approach leaves me with needing to write a function for each
message i expect


I expect there is a generic approach but it just isn't necissarily what
you where trying here. Look for something else. Maybe it involves
something you might find in the metaprogramming book....maybe not.

Apr 10 '06 #4
Noah Roberts wrote:
necissarily


Nothing personal, but these misspellings are getting a little recidivistic.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: hokieghal99 | last post by:
I wish to place all files and directories that are within a user defined path (on a Linux x86 PC) into some type of array and then examine those items for the existence of certain charaters such as...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
8
by: Hardrock | last post by:
I encountered some difficulty in implementing dynamic loop nesting. I.e. the number of nesting in a for(...) loop is determined at run time. For example void f(int n) { For(i=0; i<=K; i++)...
22
by: Technoid | last post by:
Is it possible to have a conditional if structure nested inside a conditional switch structure? switch(freq) { case 1: CASENAME if (variable==1) { do some code }
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;
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
4
by: christophe.gosiau | last post by:
Hi everybody, I have the following problem: For an application, I made 2 classes: Order and Ticket In the Order object I store an array with Ticket objects. so far so good, now I needed the Order...
27
by: aravind | last post by:
Hi, I need to develop a menu system for a project of mine. The menu will be displayed on a character LCD display driven by ARM7 Microcontroller. For this purpose i wish to construct a structure in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.