I've done similar things as this (assuming gpfile is my FILE* to the script and currfile is the
filename that I'm currently writing:
Usually I don't have an extension in my currfile (it's just data001, for example), so I don't get double-extension filenames, but if you're on a *nix that probably won't matter. (It might not matter on a Windows box either, I don't think I've tried.) Then you can just do "gnuplot gpfile", which might take a while.
fprintf(gpfile, "set terminal gif\n set xr [0,5]\n"); /* whatever your parameters are; done once */
fprintf(gpfile, "set output '%s.gif'\nplot '%s'\n"), currfile, currfile) /*after processing each file*/