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) - 1;
  11. while (*c++, *q) do while (*q == 35 ? *c != *n : *c != *q) (*c)++; while (q++, *c == *n && ++n == d);
  12. return c - d;
  13. }
  14.  
  15. int main(void)
  16. {
  17. char *result = number_format("1234567890", "(###) ###-####");
  18. char *result2 = number_format("01189998819991197253", "#### ### ### ### ### ### #");
  19. printf("%s\n", result);
  20. printf("%s\n", result2);
  21. return 0;
  22. }
Success #stdin #stdout 0s 4400KB
stdin
Standard input is empty
stdout
(123) 456-7890
0118 999 881 999 119 725 3