fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <ctype.h>
  5. #include <string.h>
  6.  
  7. static char inputBuffer[100];
  8. static char outputBuffer[100];
  9.  
  10. int isAlpha(char alpha){
  11.  
  12. if ((alpha >= 'a' && alpha <= 'z') || (alpha >= 'A' && alpha <= 'Z'))
  13. return 1;
  14. else
  15. return 0;
  16. }
  17.  
  18. int isVowel(char c)
  19. {
  20. c = tolower(c);
  21. if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
  22. return 1;
  23. return 0;
  24. }
  25.  
  26. void translate (void)
  27. {
  28. char bufferValue;
  29. char firstLetter;
  30. int j = 0, k = 0, m = 0;
  31.  
  32. printf("\n");
  33. int size = strlen(inputBuffer);
  34.  
  35. while (j < size)
  36. {
  37. bufferValue = inputBuffer[j];
  38.  
  39. if (isAlpha(bufferValue))
  40. {
  41. if (j == 0)
  42. {
  43. firstLetter = bufferValue;
  44. }
  45. else if (inputBuffer[j-1] == ' ')
  46. {
  47. firstLetter = bufferValue;
  48. }
  49. else
  50. {
  51. printf("%c", bufferValue);
  52. outputBuffer[m] = bufferValue;
  53. m++;
  54. }
  55. }
  56. else if ((bufferValue == ' ') && isAlpha(inputBuffer[j - 1]))
  57. {
  58.  
  59. outputBuffer[m] = firstLetter; m++;
  60. if (!isVowel(firstLetter)){
  61. printf("%cay%c", firstLetter, bufferValue);
  62. outputBuffer[m] = 'a';
  63. m++;
  64. }
  65. else{
  66. printf("%cy%c", firstLetter, bufferValue);
  67. }
  68. outputBuffer[m] = 'y'; m++;
  69. outputBuffer[m] = bufferValue; m++;
  70. firstLetter = ' ';
  71. }
  72. else
  73. {
  74. if (isAlpha(firstLetter)){
  75.  
  76. outputBuffer[m] = firstLetter; m++;
  77. if (!isVowel(firstLetter)){
  78. printf("%cay", firstLetter);
  79. outputBuffer[m] = 'a'; m++;
  80. }
  81. else{
  82. printf("%cy", firstLetter);
  83. }
  84. outputBuffer[m] = 'y'; m++;
  85. firstLetter = ' ';
  86. }
  87. printf("%c", bufferValue);
  88. outputBuffer[m] = bufferValue; m++;
  89. }
  90. j++;
  91.  
  92. }
  93.  
  94. printf("\n final output: %s",outputBuffer);
  95.  
  96. return;
  97. }
  98.  
  99. int main(void)
  100. {
  101. printf("enter the string\t");
  102. fflush(stdin);
  103. gets(inputBuffer);
  104.  
  105. printf ("\nInput buffer contents: %s", inputBuffer);
  106. translate();
  107. return 0;
  108. }
Success #stdin #stdout 0s 2172KB
stdin
Darrin, 0what, are you doing with 500 and 100?
stdout
enter the string	
Input buffer contents:  Darrin, 0what, are you doing with 500 and 100?
arrinDay, 0what, reay ouyay oingday ithway 500 nday 100?
 final output: arrinDay, 0what, reay ouyay oingday ithway 500 nday 100?