Advertisement
f30ghost

ex_4

Nov 23rd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. #define MAX_LEN 1000
  7.  
  8. int i;
  9. int check_vowel(char a)
  10. {
  11.     //printf("%s %c\n", __FUNCTION__, a);
  12.     if (a >= 'A' && a <= 'Z')
  13.         a = a + 'a' - 'A';
  14.  
  15.     if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
  16.         return 1;
  17.  
  18.     return 0;
  19. }
  20.  
  21.  
  22. char* toggleMarginalVowels(char s[]){
  23.     int last_pos = 0;
  24.  
  25.     for(i; s[i] != '\0'; i++){
  26.         if(check_vowel(s[i]) == 1){
  27.             if(islower(s[i])){
  28.                 s[i] = toupper(s[i]);
  29.                 }
  30.             else
  31.                 s[i] = tolower(s[i]);
  32.             while(!isspace(s[i])){
  33.                 if(check_vowel(s[i]) == 1)
  34.                     last_pos = i;
  35.                 i++;
  36.             }
  37.             if(islower(s[last_pos])){
  38.                 s[last_pos] = toupper(s[last_pos]);
  39.                 //printf("upper*  ");
  40.                 }
  41.             else
  42.                 s[last_pos] = tolower(s[last_pos]);
  43.  
  44.         }
  45.  
  46.     }
  47.     printf("%s \n", s);
  48. }
  49.  
  50.  
  51. int main()
  52. {
  53.     char string[MAX_LEN] = "This is a good one";
  54.     toggleMarginalVowels(string);
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement