pigyc
asked on
system( ) using cp
hi,
need help immediately for a c system call. I tried to copy one file from one directory to anther directory but did not workout. if do i this it will work:
system("cp /home/test/work/a.txt /home/test/ready/b.txt")
but if i do this it did not work, any hints ?:
#define PATH1 "/home/test/work/%s"
#define PATH2 "/home/test/ready/%s"
char file11[256], file2[256];
sprintf(file1, PATH1, "a.txt");
sprintf(file2, PATH2, "b.txt");
system("cp file1 file2");
need help immediately for a c system call. I tried to copy one file from one directory to anther directory but did not workout. if do i this it will work:
system("cp /home/test/work/a.txt /home/test/ready/b.txt")
but if i do this it did not work, any hints ?:
#define PATH1 "/home/test/work/%s"
#define PATH2 "/home/test/ready/%s"
char file11[256], file2[256];
sprintf(file1, PATH1, "a.txt");
sprintf(file2, PATH2, "b.txt");
system("cp file1 file2");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks all. Both are good answers.
cp file1 file2, not your actual command string.
instead do this
#define PATH1 "/home/test/work/%s"
#define PATH2 "/home/test/ready/%s"
char file1[256], file2[256];
char commandstring[100];
sprintf(file1, PATH1, "a.txt");
sprintf(file2, PATH2, "b.txt");
sprintf(commandstring, "cp %s %s", file1, file2);
system(commandstring);