fork(1) download
  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. int str_cut(char *str, int begin, int len)
  7. {
  8. int l = strlen(str);
  9.  
  10. if (len < 0) len = l - begin;
  11. if (begin + len > l) len = l - begin;
  12. memmove(str + begin, str + begin + len, l - len + 1);
  13.  
  14. return len;
  15. }
  16.  
  17. int main(void)
  18. {
  19. char str[] = "The quick brown fox";
  20.  
  21. puts(str);
  22.  
  23. str_cut(str, 10, 6); // "The quick [brown ]fox"
  24. puts(str); // "The quick fox"
  25.  
  26. str_cut(str, 3, 6); // "The [quick ]fox"
  27. puts(str); // "The fox"
  28.  
  29. str_cut(str, 3, -1); // "The[ fox]"
  30. puts(str); // "The"
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
The quick brown fox
The quick fox
The fox
The