If you invoke the program as follows:
program.exe 1.dat 2.dat
Then the main() routine of program.exe will receive argc, and argv as follows:
argc = 3
argv[0] = "program.exe"
argv[1] = "1.dat"
argv[2] = "2.dat"
Main Topics
Browse All Topicshello I am looking how to copy a file in C
I mean
like this :
in ms dos prompt I will prompt
program.exe 1.dat 2.dat
and 1.dat will be copied to 2.dat ( I dont know how to use argc argv , I would appreciate if you can explain this)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
#include <stdio.h>
#define buflen 1000
char buffer[buflen];
int main( int argc, char *argv[] ){
FILE *F,*T;
int n;
if( argc != 3 ){
printf("usage: %s from to\n",argv[0]);
exit(1);
}
if( !(F=fopen(argv[1],"r")) ){
perror(argv[1]);
exit(1);
}
if( !(T=fopen(argv[2],"w")) ){
perror(argv[2]);
exit(1);
}
while( n = fread(buffer,1,buflen,F) ){
fwrite(buffer,1,n,T);
}
}
But the stdio library takes care of matching buffer sizes to file systems' preferred block sizes, so the buffer size you use in a stdio-using program makes no difference in the size and alignment of the read and write transactions with the actual disk device.
But I, too, would have chosen a larger buffer size.
And, if you're looking for efficiency, I'd probably forego the use of stdio calls entirely.
Business Accounts
Answer for Membership
by: theMuzzPosted on 2003-10-22 at 12:49:32ID: 9601636
/* argc will give you the number of arguments you've passed
argv[] returns the values for each argument
int main(int argc, char* argv[])
{
int numberOfArguments;
numberOfArguments = argc;
string arg1, arg2, arg3; // and so on
arg1 = argv[0];
arg2 = argv[1];
arg3 = argv[2];
}
Can't remember if first argument is argv[0] or argv[1], I'm pretty sure it's 0.
so... program.exe three small arguments
would result in
arg1 = 'three'
arg2 = 'small'
arg3 = 'arguments'
Hope this helps