nikolas_serafini

Lista 9 - Exercício 3

Aug 23rd, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char* monthSearch(char month[]);
  6.  
  7. int main(int argc, char* argv[]){
  8.    
  9.     int token = 2000 + atoi(argv[3]);
  10.     char *p;
  11.     p = monthSearch(argv[2]);
  12.     printf("%s de %s de %d \n",argv[1],p,token);
  13.    
  14.  
  15.     return 0;
  16. }
  17.  
  18. char* monthSearch(char month[]){
  19.     int digit = atoi(month);
  20.     char s[15];
  21.    
  22.     if(digit == 1)
  23.         strcpy(s, "janeiro");
  24.     else if(digit == 2)
  25.         strcpy(s, "fevereiro");
  26.     else if(digit == 3)
  27.         strcpy(s, "marco");
  28.     else if(digit == 4)
  29.         strcpy(s, "abril");
  30.     else if(digit == 5)
  31.         strcpy(s, "maio");
  32.     else if(digit == 6)
  33.         strcpy(s, "junho");
  34.     else if(digit == 7)
  35.         strcpy(s, "julho");
  36.     else if(digit == 8)
  37.         strcpy(s, "agosto");
  38.     else if(digit == 9)
  39.         strcpy(s, "setembro");
  40.     else if(digit == 10)
  41.         strcpy(s, "outubro");
  42.     else if(digit == 11)
  43.         strcpy(s, "novembro");
  44.     else
  45.         strcpy(s, "dezembro");
  46.  
  47.     char *p = s;
  48.     return p;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment