nikolas_serafini

Lista 9 - Exercício 4

Aug 23rd, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char* monthSearch(char month[]);
  6. void optionOne(int argc, char* argv[]);
  7. void optionTwo(int argc, char* argv[]);
  8. void optionThree(int argc, char* argv[]);
  9.  
  10. int main(int argc, char* argv[]){
  11.    
  12.     if (strcmp(argv[1],"-f1") == 0)
  13.         optionOne(argc, argv);
  14.     else if (strcmp(argv[1],"-f2") == 0)
  15.         optionTwo(argc, argv);
  16.     else if (strcmp(argv[1],"-f3") == 0)
  17.         optionThree(argc, argv);
  18.  
  19.     return 0;
  20. }
  21.  
  22. void optionOne(int argc, char* argv[]){
  23.     int token = 2000 + atoi(argv[4]);
  24.     char *p;
  25.     p = monthSearch(argv[3]);
  26.     printf("%s de %s de %d \n",argv[2],p,token);
  27. }
  28.  
  29. void optionTwo(int argc, char* argv[]){
  30.     int token = 2000 + atoi(argv[4]);
  31.     printf("%s/%s/%d \n",argv[2],argv[3],token);
  32. }
  33.  
  34. void optionThree(int argc, char* argv[]){
  35.     int i,token = 2000 + atoi(argv[4]);
  36.     char *p;
  37.     p = monthSearch(argv[3]);
  38.     printf("%s-",argv[2]);
  39.     for(i = 0; i<3; i++)
  40.         printf("%c",p[i]);
  41.     printf("-%d \n",token);
  42. }
  43.  
  44. char* monthSearch(char month[]){
  45.     int digit = atoi(month);
  46.     char s[15];
  47.    
  48.     if(digit == 1)
  49.         strcpy(s, "janeiro");
  50.     else if(digit == 2)
  51.         strcpy(s, "fevereiro");
  52.     else if(digit == 3)
  53.         strcpy(s, "marco");
  54.     else if(digit == 4)
  55.         strcpy(s, "abril");
  56.     else if(digit == 5)
  57.         strcpy(s, "maio");
  58.     else if(digit == 6)
  59.         strcpy(s, "junho");
  60.     else if(digit == 7)
  61.         strcpy(s, "julho");
  62.     else if(digit == 8)
  63.         strcpy(s, "agosto");
  64.     else if(digit == 9)
  65.         strcpy(s, "setembro");
  66.     else if(digit == 10)
  67.         strcpy(s, "outubro");
  68.     else if(digit == 11)
  69.         strcpy(s, "novembro");
  70.     else
  71.         strcpy(s, "dezembro");
  72.  
  73.     char *p = s;
  74.     return p;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment