Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expected ';' at end of declaration list c when i have one already

Tags:

c

Im trying to declare and array in a structure called bread, but it keeps giving me the error expected ';' at end of declaration list when i already have one.

typedef struct
{
   char bread[9][35] = {
   "1. 9-Grain Wheat", 
   "2. 9-Grain Honey Oat", 
   "3. Italian", 
   "4. Italian Herbs & Cheese",
   "5. Flatbread (not baked in restaurant)", 
   "6. Cheese Bread", 
   "7. Hearty Italian", 
   "8. Parmesan Oregano", 
   "9. Roasted Garlic" };        
} subway;

this is the contents of the header file the structure is in

like image 369
Andrew Russo Avatar asked Jan 06 '23 20:01

Andrew Russo


1 Answers

You can't initialize a structure in a typedef. You have to do it when you define a variable of that type:

typedef struct
{
   char bread[9][50];   // the longest string is 38 characters, so the second dimension 
                        // should be at least 39 (38 plus the null terminating byte)
                        // we'll round up to 50 to leave space for expansion
} subway;

subway s = {{
   "1. 9-Grain Wheat",
   "2. 9-Grain Honey Oat",
   "3. Italian",
   "4. Italian Herbs & Cheese",
   "5. Flatbread (not baked in restaurant)",
   "6. Cheese Bread",
   "7. Hearty Italian",
   "8. Parmesan Oregano",
   "9. Roasted Garlic"
}};
like image 104
dbush Avatar answered Feb 01 '23 02:02

dbush