Advertisement
lukhavi

LeeMeses

May 22nd, 2020
1,670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. #define PRINT(x)        (printf("Soy %s\n",str[x]))
  7. #define MESES 12
  8. enum Mes
  9.         {
  10.                 ENERO = 0       ,       FEBRERO ,
  11.                 MARZO           ,       ABRIL   ,
  12.                 MAYO            ,       JUNIO   ,
  13.                 JULIO           ,       AGOSTO  ,
  14.                 SEPTIEMBRE      ,       OCTUBRE ,
  15.                 NOVIEMBRE       ,       DICIEMBRE
  16.         };
  17.  
  18. static char *str[] =
  19.         {
  20.                 "ENERO"         ,       "FEBRERO"       ,
  21.                 "MARZO"         ,       "ABRIL"         ,
  22.                 "MAYO"          ,       "JUNIO"         ,
  23.                 "JULIO"         ,       "AGOSTO"        ,
  24.                 "SEPTIEMBRE"    ,       "OCTUBRE"       ,
  25.                 "NOVIEMBRE"     ,       "DICIEMBRE"
  26.         };
  27. int main(void){
  28.  
  29.         int i,j;
  30.         char mesInput[MESES];
  31.         bool seguirDoWhile = true;
  32.  
  33.  
  34.         do{
  35.                 printf("\nIngrese el mes en letras:\n");
  36.                 scanf("%s",mesInput);
  37.  
  38.                 for(i=0;i<MESES;i++){
  39.                         for(j = 0;mesInput[j];j++)
  40.                                  mesInput[j] = toupper(mesInput[j]);
  41.                         if(!strcmp(str[i],mesInput)){
  42.                                 seguirDoWhile = false;
  43.                                 break;
  44.                         }
  45.                 }
  46.  
  47.         }while(seguirDoWhile);
  48.  
  49. switch(i)
  50.         {
  51.                 case ENERO      :       PRINT(ENERO)            ;       break;
  52.                 case FEBRERO    :       PRINT(FEBRERO)          ;       break;
  53.                 case MARZO      :       PRINT(MARZO)            ;       break;
  54.                 case ABRIL      :       PRINT(ABRIL)            ;       break;
  55.                 case MAYO       :       PRINT(MAYO)             ;       break;
  56.                 case JUNIO      :       PRINT(JUNIO)            ;       break;
  57.                 case JULIO      :       PRINT(JULIO)            ;       break;
  58.                 case AGOSTO     :       PRINT(AGOSTO)           ;       break;
  59.                 case SEPTIEMBRE :       PRINT(SEPTIEMBRE)       ;       break;
  60.                 case OCTUBRE    :       PRINT(OCTUBRE)          ;       break;
  61.                 case NOVIEMBRE  :       PRINT(NOVIEMBRE)        ;       break;
  62.                 case DICIEMBRE  :       PRINT(DICIEMBRE)        ;       break;
  63.                 default:
  64.                         printf("Error: Mes desconocido\n");
  65.         }
  66.  
  67.         return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement