I am trying to return a C string from a function, but it's not working. Here is my code.
char myFunction()
{
return "My String";
}
In main I am calling it like this:
int main()
{
printf("%s", myFunction());
}
I have also tried some other ways for myFunction, but they are not working. For example:
char myFunction()
{
char array[] = "my string";
return array;
}
Note: I am not allowed to use pointers!
Little background on this problem:
There is function which is finding out which month it is. For example, if it's 1 then it returns January, etc.
So when it's going to print, it's doing it like this: printf("Month: %s",calculateMonth(month));. Now the problem is how to return that string from the calculateMonth function.