#include #include enum skyColor {blue, orange, gray}; // Foregoes the use of typedef. struct forecastStruct { // Now the struct has a name. double temperature; char *message; }; // Return type needs both the "struct" keyword and the struct name. // Parameter needs both the "enum" keyword and the enum name. struct forecastStruct forecast (enum skyColor c) { // Pointer declaration without typedef. struct forecastStruct *fInfoPtr; // Note the full type specification for sizeof and the cast. fInfoPtr = (struct forecastStruct *) malloc (sizeof (struct forecastStruct) * 1); if (c == blue) { fInfoPtr->message = "Sunny and warm!"; // Note the use of the "->" operator fInfoPtr->temperature = 85.5; // because fInfoPtr is a pointer. } else if (c == orange) { fInfoPtr->message = "Enjoy the sunset"; fInfoPtr->temperature = 77.3; } else if (c == gray) { fInfoPtr->message = "Stay inside"; fInfoPtr->temperature = 64.7; } return *fInfoPtr; // Return the struct itself, not the pointer. } int main () { // Example of struct variable declaration: struct forecastStruct fInfo; fInfo = forecast (blue); // Note the use of the "." operator to access struct members. printf ("Temperature = %lf: %s\n", fInfo.temperature, fInfo.message); }