initializing multidimentional arrays
initializing multidimentional arrays
(OP)
Could somebody please help me, it’s all just getting a little to frustrating!!
I was initially working with a long .c file. Within this file I had declared a global char variable of month, with the following syntax…
char month[13][4] = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
It worked just fine, declared initialised etc everything knows where to go.
I then fiddled the program to make it modular. Therefore month is declared in the .h file.
When I subsequently try to initialise the array in the main method I just get a syntax error.
I’m trying to initialise it by writing….
month[1][ ] = “Jan”;
month[2][ ] = “Feb”;
etc
Is this completely wrong??
I was initially working with a long .c file. Within this file I had declared a global char variable of month, with the following syntax…
char month[13][4] = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
It worked just fine, declared initialised etc everything knows where to go.
I then fiddled the program to make it modular. Therefore month is declared in the .h file.
When I subsequently try to initialise the array in the main method I just get a syntax error.
I’m trying to initialise it by writing….
month[1][ ] = “Jan”;
month[2][ ] = “Feb”;
etc
Is this completely wrong??





RE: initializing multidimentional arrays
sprintf(month[1],"%s","Jan");
RE: initializing multidimentional arrays
char *month[12];
Then in the routine where you want to initialize the values,
month[0] = "Jan";
or equivalent programming. You can assign the pointer; you cannot assign a character array.