Q:

How to write a text file in another with editing in C

So I'm pretty new to files, and I'm making a function that is supposed to copy the text from a file to another and writing a number instead of ?. This was my initial approach:
void generate(int n, const int numbers[]){

    FILE *tpl = fopen("code.tpl", "r");
    FILE *file = fopen("code.c", "w");
    char text[N];
    int i, j;

    fgets(text, N, tpl);

    for(i = 0; i < N; i++){
        if(text[i] == '?'){
            text[i]= ' ';
            fprintf(file, "%d", n);
        }
        fprintf(file, "%c", text[i]);
    }

      fclose(file);
      fclose(tpl);

}

The code doesn't work and it writes an unreadable character in code.c

A:

The unreadable characters are probably because the line is shorter than N characters, so you're copying uninitialized characters to the output file. The loop should stop when it reaches the null terminator in text.
There's also no need to use fprintf() just to write a single character, use the simpler fputc(). And instead of replacing text[i] with a space, you can include that in the format string when writing n.
    for(i = 0; text[i] != 0; i++){
        if(text[i] == '?'){
            fprintf(file, "%d ", n);
        } else {
            fputc(text[i], file);
        }
    }

If the file has multiple lines, you need to read the lines in a loop, not just a single line:
while (fgets(text, N, tpl)) {
    for(i = 0; text[i] != 0; i++){
        if(text[i] == '?'){
            fprintf(file, "%d ", n);
        } else {
            fputc(text[i], file);
        }
    }
}

