How about something like this
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *ifp, *ofp;
int i, c;
if (argc < 3)
{
printf("Args needed\nEG: mycopy source target1 target2 target3 ...");
return(EXIT_FAILURE);
}
if ((ifp = fopen(argv[1], "rb")) == NULL)
{
perror(argv[1]);
return(EXIT_FAILURE);
}
for (i = 2; i < argc; i++)
{
printf("copying to %s\n", argv[i]);
if ((ofp = fopen(argv[i], "wb")) == NULL)
{
perror(argv[i]);
continue;
}
while ((c = fgetc(ifp)) != EOF && fputc(c, ofp) != EOF)
;
if (ferror(ofp)) perror(argv[i]);
if (ferror(ifp) || !feof(ifp)) perror(argv[1]);
fclose(ofp);
rewind(ifp);
}
fclose(ifp);
return(EXIT_SUCCESS);
}