This is ment to be in C code Write a function called previou

This is ment to be in C code. Write a function called previous_month() that returns the previous month. Start with the code

enum month {jan = 1, feb, …, dec};

typedef enum month month;

If dec is passed as an argument to the function, nov should be returned.

Any help would be appreciated. thank you

Solution

#include<stdio.h>
#include <string.h>
enum month {Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec};
typedef enum month months;

char *getMonth(enum month mon){
switch (mon)
{
case Jan: return \"Jan\";
case Feb: return \"Feb\";
case Mar: return \"Mar\";
case Apr: return \"Apr\";
case May: return \"May\";
case Jun: return \"Jun\";
case Jul: return \"Jul\";
case Aug: return \"Aug\";
case Sep: return \"Sep\";
case Oct: return \"Oct\";
case Nov: return \"Nov\";
case Dec: return \"Dec\";
}
}
char *previous_month(char *curr){
   char *prevMonth;
   int i;
  
   for( i=2;i<13;i++){
       if(strcmp(curr,getMonth((months)i))==0){
           prevMonth=getMonth((months)(i-1));
           return prevMonth;
       }
   }
   return \"\";
}

int main()
{
   char x[3];
   char *y;
printf(\"please enter the month\ \");
scanf(\"%s\",x);
y=previous_month(x);
printf(\"%s\",y);
return 0;
}

This is ment to be in C code. Write a function called previous_month() that returns the previous month. Start with the code enum month {jan = 1, feb, …, dec}; t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site