This is a program i coded which parses command line arguments which are expected to be text files and in turn send contents to STDOUT which is screen.

it compiles but doesn't work. although it compiles. sinces its run from the commandline, i dont know how to debug such programs. can anyone tell me how to do this? i mean how to debug command line arguments.

this is the source code for the program;

Code:
#include <stdio.h>


void filecopy(FILE *, FILE *);
int main(int argc, char *argv[]){
    FILE *fp;
    if (argc == 1){
        filecopy(stdin, stdout);
    }
    else
       while (--argc > 0)
            if ( (fopen(*++argv, "r")) == NULL ){
                printf("could not open file: %s", *argv);
                continue;
            }
            else {
                filecopy(fp, stdout);
                fclose(fp);
            }


    return 0;

}


void filecopy(FILE *ifp, FILE *ofp){
    int c;
    if (ifp == NULL || ofp == NULL)
        return;
    else
        while ( (c = getc(ifp)) != EOF)
        putc(c, ofp);
}