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

You forgot to specify the true value of argv[0], namely execl("/bin/cp","/bin/cp","../data/data_.txt","../data/data.txt",(char*)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?

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.

Put down your code down here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.