Click here to Skip to main content
14,970,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the technique for getting output using command line argument through vc++


here in following program that is:

#include "stdio.h"
main ( int argc, char *argv[ ] )
{
FILE *fs, *ft ;
char ch ;
if ( argc != 3 )
{
puts ( "Improper number of arguments" ) ;
exit( ) ;
}
fs = fopen ( argv[1], "r" ) ;
if ( fs == NULL )
{
puts ( "Cannot open source file" ) ;
exit( ) ;
}
ft = fopen ( argv[2], "w" ) ;
if ( ft == NULL )
{
puts ( "Cannot open target file" ) ;
fclose ( fs ) ;
exit( ) ;
}
while ( 1 )
{
ch = fgetc ( fs ) ;
if ( ch == EOF )
break ;
else
fputc ( ch, ft ) ;
}
fclose ( fs ) ;
fclose ( ft ) ;
}


when i run in vc++ compiler it always show to me about that "Improper number of arguments".
but how i will run through command prompt to copy one file to another, as it always shows the following statement.

is there any mistake i have.
plz tell me.....
Posted
Updated 4-Jan-10 14:47pm
v2

wrote:
when i run in vc++ compiler it always show to me about that "Improper number of arguments".


Of course. Have you configured VC to send three arguments when running the code ?

Also - I deleted your second question. I said to edit this post. I did it for you and formatted it, but asking twice is kind of rude and pollutes the forum.
   
The command line args are passed in to your main method. What do you mean by 'getting output' ? Please edit your post to add detail.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900