fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main()
  6. {
  7. char *input = (char*) malloc(22 * sizeof(char*));
  8. strcpy(input, "01");
  9. strcat(input, "2345678901234567890");
  10. printf("input is %s\n", input);
  11.  
  12. int input_len = strlen(input);
  13.  
  14. char *output = (char*) malloc((input_len + ((input_len - 1) / 7) + 1) * sizeof(char));
  15. int j = 0;
  16. for (int i = 0; i < input_len; ++i) {
  17. if (i > 0 && i % 7 == 0) {
  18. output[j++] = '-';
  19. }
  20. output[j++] = input[i];
  21. }
  22. output[j] = '\0';
  23. printf("output is %s\n", output);
  24.  
  25. free(output);
  26. free(input);
  27. return 0;
  28. }
Success #stdin #stdout 0s 5556KB
stdin
Standard input is empty
stdout
input is 012345678901234567890
output is 0123456-7890123-4567890