fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. char *number_format(char *n, char *f)
  6. {
  7. int d = 1;
  8. char *c, *q = f;
  9. while (*++f) d++;
  10. c = malloc(d);
  11. while (*q) if ((*c++ = *q++) == 35) do while (*(c - 1) != *n)*(c - 1) += 1; while (++n, *f);
  12. return c - d;
  13. }
  14.  
  15. int main(void) {
  16. char *result = number_format("1234567890", "(###) ###-####");
  17. char *result2 = number_format("01189998819991197253", "#### ### ### ### ### ### #");
  18. printf("%s\n", result);
  19. printf("%s\n", result2);
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 4296KB
stdin
Standard input is empty
stdout
(123) 456-7890
0118 999 881 999 119 725 3