As an alternative to creating two functions (as per AareP's answer), you could add a destination parameter to the output()
function:
void foutput(FILE *dest, int values[])
{
int i;
for (i=0; i<10; i++)
fprintf(dest, "%d ", values[i]);
}
You can then reimplement the original output()
as a simple wrapper:
void output(int values[])
{
foutput(stdout, values);
}
This might not seem too useful in this case, but I've put it here because this general pattern can be useful when the logic of the output function is more complicated. In general it's better to keep it in one place than to replicate it across multiple functions (it means you only have to fix bugs in one place, for one thing).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…