I am trying to declare a character string which is big enough to hold 12 variables but only initialized to hold 2.
I tried doing
char months [ 12 ] [ 2 ];
but that didnt work. I could use some help, thanks in advance.
I am trying to declare a character string which is big enough to hold 12 variables but only initialized to hold 2.
I tried doing
char months [ 12 ] [ 2 ];
but that didnt work. I could use some help, thanks in advance.
I need to declare a character string array called months which is big enough to hold 12 names, but initialized only to hold the first two names.
ignore my code i dont know what I am doing, I am new at this
So something like this?
Initalizing arrays like this will cause the rest of the array to be initalized to 0. That means all entries except the first 2 inside months will be NULL.Code:char *months[12] = {"Month 1", "Month 2"};
And also the first two entries are immutable (read-only).
Yes and no. The strings themselves are not editable, but you can make the pointers point elsewhere. You also can make them safely point elsewhere without worrying about a memory leak in this particular case, since you're using string literals.
Quzah.
Hope is the first step on the road to disappointment.