i wrote this prog to read in a file and number all but the blank lines and write to another fill all of the lines including non numbered blanks it worked fine but now i want to get the input and output files from the command line i cant figure out why this doesnt work it compiles and runs but it doesnt wright anything to the output file PLEASE HELP
#include <stdio.h>
#include <string.h>
#define MAXLEN 81
#define NUMARG 5
int main (int argc, char *argv[])
{
char buffer[MAXLEN];
FILE *finp, *foutp;
unsigned int line_number=0;
if (argc != NUMARG)
{
printf("usage : p2 infile outfile -m -u\n");
exit (1);
}
if ((finp = fopen(argv[1], "r")) == NULL)
{
printf("could not open file %s for reading. \n", argv[1]);
exit (1);
}
if ((foutp =fopen(argv[2], "w")) == NULL)
{
printf("could not open file %s for writing.\n", argv[2]);
exit(1);
}
/* count non empty lines */
/*output all lines*/
while (fgets(buffer, sizeof buffer, finp))
{
if(strlen(buffer)>1)
if(fprintf(foutp, "%u", ++line_number)<=0)
break;
if(fprintf(foutp, "%s",buffer)<=0)
break;
}
if (fclose(finp) == EOF)
{
printf("error in closing file input.dat.\n");
}
if (fclose(foutp) == EOF)
{
printf("error in closing output.dat.\n");
}
return 0;
} /*end of main */