fork download
  1. #include <ctype.h>
  2. #include <stdio.h>
  3.  
  4. size_t change(char *dst, size_t n, const char *src) {
  5. size_t nn = 1; // for the zero terminator
  6. static char cvt[][2][99] = {{"a", "AUAU"},
  7. {"e", "-------"},
  8. {"u", "AUAUAUAUAU"}};
  9. while (*src) {
  10. if (nn == n) break;
  11. int found = 0;
  12. for (int i = 0; i < sizeof cvt / sizeof *cvt; i++) {
  13. if (tolower(*src) == cvt[i][0][0]) {
  14. char *p = cvt[i][1];
  15. found = 1;
  16. while (*p) {
  17. *dst++ = *p++;
  18. nn++;
  19. if (nn == n) break;
  20. }
  21. break;
  22. }
  23. }
  24. if (!found) {
  25. *dst++ = *src;
  26. nn++;
  27. }
  28. src++;
  29. }
  30. *dst = 0;
  31. return nn;
  32. }
  33.  
  34. int main(void) {
  35. char x[99];
  36. int n;
  37. n = change(x, 99, "Gustavo");
  38. printf("Gustavo ==> %s (%d)\n", x, n);
  39. }
  40.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Gustavo ==> GAUAUAUAUAUstAUAUvo (20)