I am not new to programming however I am very new to C programming and I've been looking around on here for some help on a homework question and can't seem to find an answer.
Context: We have been asked to take a month input from the user and determine which season that month is in and print it out.
The Problem: I'm trying to declare a character array variable (season) using the output of a function in C.
Java Example: String season = determineSeason(month);
What I have right now is (not the whole program):
char month[10];
printf("Enter a month: ");
scanf("%s", month);
char season[7] = detSeason(month);
printf("season: %s", season);
char* detSeason(char month[10])
{
char season[7];
if ((strcmp(month, "september")) == 0 || (strcmp(month, "october")) == 0 || (strcmp(month, "november")) == 0)
{
return strcpy(season, "Spring");
}
The issue I'm having is with the line char season[7] = detSeason(month);
The error I am getting is: array initializer must be an initializer list or string literal
My guess is that it's trying to use the function call as the string literal and not actually calling the function and storing the output in the variable.
Could someone please let me know what I am doing wrong.
Note: I have cut off the rest of the else if statements to not make this post too long, but it follows the same format as the first if statement.
Thank you in advance :)
p.s. Does anyone know why it won't let me put "Hello," at the start of my post, it keeps cutting it off?