[Cpp-Programming] file copy program with arguments taken in main function
This what my code is :
===========================
# 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 ;
}
=========================
I use GNU gcc Compiler in Linux system.
Now The code basically should take 2 files as input and copy from one
file to another. So, I opened terminal at entered < filecopy file1.txt
file2.txt > but its showing some errors.
How should I do run this in terminal so as to successfully run this
code.
< source code file, file1.txt and file2.txt are stored in the default
location where generally C stores a.out >
--
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to cpp-programming@googlegroups.com.
To unsubscribe from this group, send email to cpp-programming+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cpp-programming?hl=en.
0 Comments:
Post a Comment
<< Home