Okay . . . so you want to generate a filename for gnuplot to save to, correct? Then you can either pass that directly to gnuplot for its output file, or rename gnuplot's output file to this new name.

Well, I think sprintf() would work well here, as you mentioned earlier.
Code:
sprintf(filename, "file-%d.output", number);
Then, when you execute gnuplot, use filename. If you're using system, consider something like (I don't know gnuplot's arguments):
Code:
sprintf(command, "gnuplot %s -o %s", input, output);
system(command);
With exec*(), just pass output as another argument.

You'll have to be more specific. How are you calling gnuplot?