473,404 Members | 2,137 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,404 software developers and data experts.

list of strings

Hi all,

I have a strange problem occuring when i declare an array of strings in
ANSI C style:

if i have something like :

struct blabla {

//...
char *names[] = {"name1","name2", "name3" };

};

, it doesn't work. But if i declare it by itself (not in a struct - i.e
for instance in the outmost scope of any function) , it works. What am
i doing wrong? Thanks a lot.

Dec 6 '05 #1
6 7143
"todorov" <at*******@gmail.com> writes:
I have a strange problem occuring when i declare an array of strings in
ANSI C style:

if i have something like :

struct blabla {

//...
char *names[] = {"name1","name2", "name3" };

};

, it doesn't work. But if i declare it by itself (not in a struct - i.e
for instance in the outmost scope of any function) , it works. What am
i doing wrong? Thanks a lot.


A struct member declaration can't include an initializer.

You can initialize a struct member as part of the initializer for a
struct object.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 6 '05 #2

"todorov" <at*******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi all,

I have a strange problem occuring when i declare an array of strings in
ANSI C style:

if i have something like :

struct blabla {

//...
char *names[] = {"name1","name2", "name3" };

};

, it doesn't work. But if i declare it by itself (not in a struct - i.e
for instance in the outmost scope of any function) , it works. What am
i doing wrong? Thanks a lot.


struct blabla {
char *names[3];
} bla = {{"name1", "name2", "name3"}};

-Mike
Dec 6 '05 #3
todorov a écrit :
struct blabla {

//...
char *names[] = {"name1","name2", "name3" };

};


Wrong way. Try this :

struct blabla {
//...
char *names[] = {"name1","name2", "name3" };
}
=
{
//... ,
{"name1", "name2", "name3"},
};

--
A+

Emmanuel Delahaye
Dec 6 '05 #4
todorov a écrit :
struct blabla {

//...
char *names[] = {"name1","name2", "name3" };

};


Wrong way. Try this :

struct blabla {
//...
char **names;
}
=
{
//... ,
{"name1", "name2", "name3"},
};

--
A+

Emmanuel Delahaye
Dec 6 '05 #5
Emmanuel Delahaye wrote:
todorov a écrit :
struct blabla {

//...
char *names[] = {"name1","name2", "name3" };

};

Wrong way. Try this :

struct blabla {
//...
char **names;


You can't initialise a scalar with more than one element. This should be
char *names[3];
}
The name of the object you are declaring is missing.
=
{
//... ,
{"name1", "name2", "name3"},
};


--
Simon.
Dec 7 '05 #6
On 6 Dec 2005 04:46:36 -0800, "todorov" <at*******@gmail.com> wrote:
Hi all,

I have a strange problem occuring when i declare an array of strings in
ANSI C style:

if i have something like :

struct blabla {

//...
char *names[] = {"name1","name2", "name3" };

};

, it doesn't work. But if i declare it by itself (not in a struct - i.e
for instance in the outmost scope of any function) , it works. What am
i doing wrong? Thanks a lot.


That is not an array of strings. It is an array of pointers.
<<Remove the del for email>>
Dec 17 '05 #7

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

Similar topics

17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
7
by: Klaus Neuner | last post by:
Hello, I need a function that converts a list into a set of regexes. Like so: string_list = print string_list2regexes(string_list) This should return something like:
21
by: Timothy Babytch | last post by:
Hi all. I have a list that looks like , , ] I try to make it flat one: How can I archieve such an effect with list comprehension? Two cycles did the job, but that way did not look pythonic.....
7
by: David. E. Goble | last post by:
Hi all; I need to build a list of strings in one function and use the list in another function. ie buildlist(char list, FILE **infile); { int i;
5
by: Someone | last post by:
I wish to use a sorted list to store lists of strings. I am unsure as to how things work. I want to do something like: SortedList list = new SortedList(); for(...loop for string...) { if( !...
27
by: Tripper | last post by:
Which is the better way to go and why? //trivial example List<string> strings = GetStrings(); foreach (string s in strings) { // some operation; } strings.ForEach(
5
by: Jimp | last post by:
Why can't I cast List<MyObject> to ICollection<IMyObject>. MyObject implements IMyObject, and of course, List implements ICollection. Thanks
9
by: Paul | last post by:
Hi, I feel I'm going around circles on this one and would appreciate some other points of view. From a design / encapsulation point of view, what's the best practise for returning a private...
8
by: dmp | last post by:
What are Linked list? Please somebody show some ready made programs of linked list
6
by: dudeja.rajat | last post by:
Hi, How to check if something is a list or a dictionary or just a string? Eg: for item in self.__libVerDict.itervalues(): self.cbAnalysisLibVersion(END, item) where __libVerDict is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.