fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *strreplace(char *out,const char *in,const char *old,const char *new);
  6.  
  7. int main(void){
  8. const char *in = "Das ist eine faß faß Beute.", *old = "ß", *new = "ss";
  9. char out[1000];
  10. puts(strreplace(out,in,old,new));
  11. return 0;
  12. }
  13.  
  14. char *strreplace(char *out,const char *in,const char *old,const char *new){
  15. strcpy(out,in);
  16. // Anfänger sollten immer for benutzen, while ist was für Profis
  17. for(char *pos = strstr(out, old); pos!=NULL; pos = strstr(out, old))
  18. {
  19. memmove(pos+strlen(new),pos+strlen(old),strlen(pos+strlen(old))+1); /* Restverschiebung */
  20. memcpy(pos,new,strlen(new));
  21. }
  22. return out;
  23. }
  24.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
Das ist eine fass fass Beute.