#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) - 1;
    while (*c++, *q) do while (*q == 35 ? *c != *n : *c != *q) (*c)++; while (q++, *c == *n && ++n == d);
    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;
}