Basically there are two different ways to think about / talk about strings:
An array of characters, terminated by a '\0' character. (This is the formal definition of a string in C.)
As a pointer to character, or char *, pointing at the first of a sequence (an array) of characters, terminated by a '\0' character.
So you can declare an array, and copy a string into it:
char arraystring[10];
strcpy(arraystring, "Hello");
Or you can declare an array, and give it an initial value when you declare it:
char arraystring2[] = "world!";
Or you can declare a pointer, and make it point to a string:
char *pointerstring;
pointerstring = "Goodbye";
Or you can declare a pointer, and give it an initial value:
char *pointerstring2 = "for now";
It's worth knowing how these "look" in memory:
+---+---+---+---+---+---+---+---+---+---+
arraystring: | H | e | l | l | o |\0 |\0 |\0 |\0 |\0 |
+---+---+---+---+---+---+---+---+---+---+
+---+---+---+---+---+---+---+
arraystring2: | w | o | r | l | d | ! |\0 |
+---+---+---+---+---+---+---+
+---------------+
pointerstring: | * |
+-------|-------+
| +---+---+---+---+---+---+---+---+
+---------> | G | o | o | d | b | y | e |\0 |
+---+---+---+---+---+---+---+---+
+---------------+
pointerstring2: | * |
+-------|-------+
| +---+---+---+---+---+---+---+---+
+---------> | f | o | r | | n | o | w |\0 |
+---+---+---+---+---+---+---+---+
Now, the thing is, you can't assign arrays in C. You can assign pointers. You can also make use of the special rule (the "equivalence between arrays and pointers") by which when you use an array in an expression, what you get is a pointer to the array's first element.
So if you want to assign one string-as-pointer to another string-as-pointer, that works:
pointerstring = pointerstring2;
If you try to assign one string-as-array to another string-as-array, that doesn't work
arraystring = arraystring2; /* WRONG -- compiler complains, attempt to assign array */
If you want to copy one string-as-array to another, you have to call strcpy (and of course you have to worry about overflow):
strcpy(arraystring, arraystring2);
You can also assign a string-as-array to a string-as-pointer:
pointerstring = arraystring;
This works because the compiler treats it exactly as if you'd written
pointerstring = &arraystring[0];
Finally, if you attempt to assign a string-as-pointer to a string-as-array, this doesn't work, again because you can't assign to an array:
arraystring = pointerstring; /* WRONG */
Again, you could call strcpy instead, as long as you're sure the string will fit:
strcpy(arraystring, pointerstring); /* but worry about overflow */
In your original code, mname was a string-as-array, so you can't assign to it. You have two choices:
Use strcpy to copy strings into it:
if (mm == 1) { strcpy(mname, "January"); }
Declare mname as p a pointer instead:
char *mname;
...
if (mm == 1) { mname = "January"; }
Addendum: For completeness, I should mention one more set of points.
When you initialize a pointer to point to a string, in either of these ways:
char *pointerstring = "Goodbye";
char * pointerstring2;
pointerstring2 = "for now";
those strings "Goodbye" and "for now" are read-only. You can't modify them. So if you try to do something like
strcpy(pointerstring, pointerstring2); /* WRONG: overwriting constant string */
it won't work, because you're trying to copy the second string into the memory where the first string is stored, but that memory isn't writable.
So when you're using arrays, you can't use assignment, you must use strcpy; but when you're using pointers, you can use assignment, and you probably can't call strcpy.
char mname[9];->const char *mname;static const char *months[] = { "January", "February", "March", ... }; const char *mname = months[mm - 1];(sanity check needs to be added).char mname[9]is too short to hold"September"{mname = XXX;}->{strcpy(mname, XXX;}andmname[9];->mname[10];(you need one char more for the NUL terminator).