LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-08-2011, 04:58 PM   #1
Jusctsch
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Rep: Reputation: 0
How to Initialize an array of string literals inside a structure


Hey guys,


Code:
typedef struct
{
    char      fooId[32];                                  
    char      SupportedProductList[10][32];
    FooType   type; ///enum                                                   
} foo_Index;

foo_Index foo_Table[] =
{
    {   "fooGATE",                                 // fooId
        {"1","2","3","4","5","6","7","8","9","0",} // SupportedProductList
        foo_foogateF7,      // fooType (Line 8)
    },                                 (Line 9)
};
(Where FooType is an enum)

This blows up with the following errors:
8: error: expected `}' before 'foo_foogateF7'
8: error: expected `}' before 'foo_foogateF7'
8: error: expected ',' or ';' before 'fooType_foogateF7'
9: error: expected declaration before '}' token

So, I want to have an array of size 10 chock full of string literals. Not exactly sure how to type it out when initializing a structure though.
Thanks
 
Old 11-08-2011, 05:02 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 644Reputation: 644Reputation: 644Reputation: 644Reputation: 644Reputation: 644
Code:
typedef struct
{
    char      fooId[32];                                  
    char      SupportedProductList[10][32];
    FooType   type; ///enum                                                   
} foo_Index;

foo_Index foo_Table[] =
{
    {   "fooGATE",                                 // fooId
        {"1","2","3","4","5","6","7","8","9","0",}, // SupportedProductList
        foo_foogateF7,      // fooType (Line 8)
    },                                 (Line 9)
};
Aren't you missing a comma ?
 
Old 11-08-2011, 05:22 PM   #3
Jusctsch
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by kbp View Post
Aren't you missing a comma ?
Sweet Martha's Cookies, you got it.
Thanks for the fresh eyes, sorry for the obvious question
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xemacs syntax highlighting only works on string literals! (Slackware) turbo_spool Linux - Software 3 11-22-2007 11:25 AM
java test if string in string array is null. exodist Programming 3 02-21-2004 02:39 PM
concentration of string literals with _FUNCTION_ is depreciated dzt Linux - Software 4 10-16-2003 01:38 PM
concentration of string literals with _FUNCTION_ is depreciated dzt Linux - General 0 10-16-2003 04:41 AM
How to initialize this structure only in one clause? Xiangbuilder Programming 8 08-27-2003 09:50 AM


All times are GMT -5. The time now is 10:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration