fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. char *strreplace(char *str,const char *from,const char *to)
  7.  
  8. {
  9.  
  10. char *p=str;
  11.  
  12. while( p=strstr(p,from) )
  13.  
  14. {
  15.  
  16. memmove(p+strlen(to),p+strlen(from),strlen(p+strlen(from))+1);
  17.  
  18. memcpy(p,to,strlen(to));
  19.  
  20. p+=strlen(to);
  21.  
  22. }
  23.  
  24. return str;
  25.  
  26. }
  27.  
  28.  
  29.  
  30.  
  31.  
  32. int main()
  33.  
  34. { // 3. Variante
  35.  
  36. char string3[200] = "Hallo, diese Nachricht wird ersetzt. Dieser Quelltext gehoert zu den Systemen.";
  37.  
  38. printf("Vorher: %s\n", string3); // Vorher
  39.  
  40. printf("Nachher: "); // Nachher
  41. printf(strreplace(string3,"en","x"),strreplace(string3,"x","en"), strreplace(string3,"er","q"), strreplace(string3,"q","er"), strreplace(string3,"y","ch"),strreplace(string3,"ch","y"), strreplace(string3,"a","o"), strreplace(string3,"o","a"));
  42.  
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
Vorher: Hallo, diese Nachricht wird ersetzt. Dieser Quelltext gehoert zu den Systemen.
Nachher: Hollo, diese Nochricht wird qsetzt. Diesq Quelltext gehoqt zu dx Schstemx.