>input=fopen(argv[1],"r");
>output=fopen(argv[2],"w");
This really doesn't do too much. The first thing you do is reassign input to another return from fopen, and you never use output except to break the program by fclosing it multiple times.
It looks like you want to write your own version of cat:
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
char buffer[BUFSIZ];
if (argc < 2) {
/* No input files, take input from stdin */
while (fgets(buffer, sizeof buffer, stdin) != NULL)
fputs(buffer, stdout);
}
else {
FILE *in;
int i;
for (i = 1; i < argc; i++) {
if ((in = fopen(argv[i], "r"))== NULL)
continue;
while (fgets(buffer, sizeof buffer, in) != NULL)
fputs(buffer, stdout);
}
}
return 0;
}
Of course, getting the basic functionality to work isn't the fun part. The fun part is adding all of the switch handling and nifty options that cat supports.