0

I am getting an error when I do this in C program:
execl("/bin/cp","../data/data_.txt","../data/data.txt",0);

error is as follows:
../data/data_.txt: missing destination file operand after `../data/data.txt'
Try `../data/data_.txt --help' for more information.

I tried this too, it didn't help.
execl("/bin/cp ../data/data_.txt ../data/data.txt",0);

All I am trying to do is this:
cp ../data/data_.txt ../data/data.txt

3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by kv79
0

You forgot to specify the true value of argv[0], namely execl("/bin/cp","/bin/cp","../data/data_.txt","../data/data.txt",(char*)0);

0

You forgot to specify the true value of argv[0], namely execl("/bin/cp","/bin/cp","../data/data_.txt","../data/data.txt",(char*)0);

It worked. Placing (char*) in front of 0 makes it into a NULL character?

0

No, it makes it a NULL char* pointer (which is what the variadic function execl expects).
The cast is necessary because there is no means of prototyping the variadic parameters, thus no way for the compiler to supply the correct type conversion of a bare 0.

On the off-chance that the machine representation of a char* pointer is different from what a simple integer 0 would be.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.