Ok, i've never ran a file that contains and argument in the main such as main(*****,****). When you compile the functin in Linux one types 'gcc foo.c' but then when i try and run the file './a.out' I notice that you need more than this to run the program. Ok I'm not making any sense but what I need help in is for example the program below lets call it foo.c how would i run it without getting the message "You forgot to enter the filename"
thanks
#include <stdio.h>
#include <stdlib.h>
void main(int argc, char *argv[])
{
FILE *in, *out; // file pointers
char ch;
if(argc!=3)
{
printf("You forgot to enter the filenames\n"
;
exit(1);
}
if((in=fopen(argv[1], "rb"
)==NULL) // open source file
{ // for read binary
printf("Cannot open source file\n"
;
exit(1);
}
if((out=fopen(argv[2], "wb"
)==NULL) // open dest file
{ // for write binary
printf("Cannot open destination file\n"
;
exit(1);
}
while(!feof(in)) // here it is
{
ch=getc(in);
if(!feof(in)) // and again
putc(ch,out);
}
fclose(in); // close files
fclose(out);
}
thanks
#include <stdio.h>
#include <stdlib.h>
void main(int argc, char *argv[])
{
FILE *in, *out; // file pointers
char ch;
if(argc!=3)
{
printf("You forgot to enter the filenames\n"
exit(1);
}
if((in=fopen(argv[1], "rb"
{ // for read binary
printf("Cannot open source file\n"
exit(1);
}
if((out=fopen(argv[2], "wb"
{ // for write binary
printf("Cannot open destination file\n"
exit(1);
}
while(!feof(in)) // here it is
{
ch=getc(in);
if(!feof(in)) // and again
putc(ch,out);
}
fclose(in); // close files
fclose(out);
}