How use exec, execlp, ....

Hello,

I need to do a function in ansi c for linux that work like command cp.I try with this but doesn't work:

int copy (char *src, char *dst)
{
ret = execlp("/bin/cp", "cp", "/home/linux/working", (char*)src,(char*)dst)
return 0;
}

The copy function must do the next "cp origein.txt destiny.txt" using th path directory called "/home/linux/working"

Thanks!

Did you bother to read the manpage of the execlp function...

This also sounds like homework, and my bet is that they don't want you to call the system's copy function, rather they want you to open the two files in binary and read from one and write to the other.

Read the man pages for, fopen, fread, fwrite, and fclose. You can figure out the number of bytes you need to copy with fseek and ftell.

Or, hey, just Google search the source for the cp function :).