Advertisement
lukasd

zadanie 1 zestaw 16

Jan 4th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. typedef enum{LOWERCASE,UPPERCASE,CAPITALIZED} StringMode;
  2.  
  3. bool check(const char str[], StringMode sm)
  4. {
  5.   switch (sm)
  6.   {
  7.     case LOWERCASE:
  8.       for (int i=0; str[i]!='\0'; i++)
  9.         if(str[i] >= 'A' && str[i]<='Z')
  10.           return false;
  11.       return true;
  12.     case UPPERCASE:
  13.       for(int i=0; str[i]!='\0'; i++)
  14.         if(str[i] >='a' && str[i] <='z')
  15.           return false;
  16.       return true;
  17.     case CAPITALIZED:
  18.     {
  19.       char temp[strlen(str)];
  20.       strcpy(temp, str);
  21.       char *p;
  22.       p=strtok(temp, " ");
  23.       while(p!=NULL)
  24.       {
  25.         if(p[0] >= 'a' && p[0] <= 'z')
  26.           return false;
  27.         for(int i=1; p[i]!='\0'; i++)
  28.           if(p[i] >='A' && p[i] <= 'Z')
  29.           return false;
  30.         p = strtok(NULL, " ");
  31.       }
  32.       return true;
  33.     }
  34.   }
  35. }
  36.  
  37. int main ()
  38. {
  39.   printf("%d\n", check("SDsSDAD ASDSADSD ASDFSAFS", UPPERCASE));
  40.   return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement