fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char vowels[] = {'a','e','i','o','u','A','E','I','O','U'};
  6.  
  7. int linear_search(char chr, char* str, size_t len)
  8. {
  9. int i;
  10. for (i = 0; i < len; ++i)
  11. {
  12. if (str[i] == chr)
  13. {
  14. return i;
  15. }
  16. }
  17. return -1;
  18. }
  19.  
  20. int in(char chr, char* str, size_t len)
  21. {
  22. return linear_search(chr, str, len) == -1 ? 0 : 1;
  23. }
  24.  
  25. int is_a_vowel(char chr)
  26. {
  27. return in(chr, vowels, sizeof(vowels));
  28. }
  29.  
  30. void remove_vowels(char* str, size_t len)
  31. {
  32. char* buf = malloc(sizeof(*buf)*len);
  33. int i, j=0;
  34. for (i = 0; i < len; ++i)
  35. {
  36. if (!is_a_vowel(str[i]))
  37. {
  38. buf[j] = str[i];
  39. ++j;
  40. }
  41. }
  42. memcpy(str,buf,sizeof(*str)*j);
  43. free(buf);
  44. }
  45.  
  46. int main(int argc, char *argv[])
  47. {
  48. char str[] = "Green Eggs and Ham";
  49. printf("%s\n", str);
  50. remove_vowels(str, sizeof(str));
  51. printf("%s\n", str);
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 1808KB
stdin
Standard input is empty
stdout
Green Eggs and Ham
Grn ggs nd Hm