I use Linux system with GNU gcc compiler.
I have written the following code for copying string of one file to another.
-this code mainly take two file names as input and copies from one to another.
> the program is compiled and has no errors but the problem is that when I first give input in the terminal like
PHP Code:
filecopy file1.txt file2.txt
Its saying no command exists....
the same I used in windows dos and it worked.
what kind of command should I use while giving input ?
Code:
# include <stdio.h>
# include <stdlib.h>
int main ( int argc, char *argv[] )
{
FILE *psCopy, *psPaste ;
char ch ;
if ( argc != 3 )
{
printf("Insufficient number of arguments\n");
exit (101);
}
psCopy = fopen ( argv [1], "r" );
if ( !psCopy )
{
printf ("File couldn't open. Sorry!\n");
exit (102);
}
psPaste = fopen ( argv [2], "w" );
if ( !psPaste )
{
printf ("File couldn't open. \n");
exit (201);
}
while ( (fscanf (psCopy,"%c",&ch)) == 1 )
fprintf (psPaste,"%c",ch) ;
fclose (psCopy) ;
fclose (psPaste) ;
return ;
}