fork(2) download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5. #include <ctype.h>
  6.  
  7. bool isVowel(char c) {
  8. return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
  9. }
  10.  
  11. long long int countAndPrint(const char *str)
  12. {
  13. long long int count = 0,i;
  14. int len = strlen(str);
  15. int start_index = -1;
  16. for(i=0;i<len;++i){
  17. char c = tolower(str[i]);
  18. if(isVowel(c)){
  19. if(start_index == -1) start_index = i;
  20. }else{
  21. start_index = -1;
  22. }
  23.  
  24. if(start_index != -1) count += (long long int)(i - start_index + 1);
  25. }
  26. return count;
  27. }
  28.  
  29.  
  30. int main()
  31. {
  32. printf("Number of vowel only substrings: %lld\n", countAndPrint("aeixae"));
  33. }
Success #stdin #stdout 0s 4328KB
stdin
Standard input is empty
stdout
Number of vowel only substrings: 9