#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *number_format(char *n, char *f)
{
    int d = 1;
    char *c, *q = f;
    while (*++f) d++;
    c = malloc(d);
    while (*q) if ((*c++ = *q++) == 35) do while (*(c - 1) != *n)*(c - 1) += 1; while (++n, *f);
    return c - d;
}

int main(void) {
    char *result = number_format("1234567890", "(###) ###-####");
    char *result2 = number_format("01189998819991197253", "#### ### ### ### ### ### #");
    printf("%s\n", result);
    printf("%s\n", result2);
    return 0;
}
