Advertisement
Guest User

Untitled

a guest
May 20th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *foo(const char *s, char k){
  6. int z = 0;
  7. char szo[strlen(s)];
  8. strcpy(szo,s);
  9. int hossz = strlen(s);
  10. for(int i = 0; i < hossz; i++){
  11. if(szo[i] == k || szo[i] == k-32 || szo[i] == k+32){
  12. z++;
  13. }
  14. }
  15. z = z;
  16. char szo2[hossz+z];
  17. int j = 0;
  18. for(int i = 0; i < hossz; i++){
  19.  
  20. szo2[j] = szo[i];
  21. j++;
  22. if(szo[i] == k){
  23. szo2[j] = k;
  24. j++;
  25.  
  26. }
  27. if(szo[i] == k-32){
  28. szo2[j] = k-32;
  29. j++;
  30. }
  31. if(szo[i] == k+32){
  32. szo2[j] = k+32;
  33. j++;
  34. }
  35.  
  36. }
  37. char *mutat = (char *)malloc(sizeof(szo2));
  38. strcpy(mutat,szo2);
  39. mutat[hossz+z] = '\0';
  40. return mutat;
  41. }
  42.  
  43.  
  44. int main()
  45. {
  46. char *s[] = {"asztal", "zabszem", "ablak", "szalonna", "zizzen", "Zorro"};
  47. int i;
  48. for (i = 0; i < sizeof(s) / sizeof(char *); ++i) {
  49. char *p = foo(s[i], 'z');
  50. printf("%s\n", p);
  51. free(p);
  52. }
  53. return EXIT_SUCCESS;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement