'set' is an internal command to most of the shells. You are tryin to spawn a new process with this, which is not allowed. This is why it is not working for you. On the other hand, 'ls' is an external command (physical file present in file system - /usr/bin/ls), which can be spawned.
If 'set' is a file created by you, execlp() with the full path where this file is present.
setenv() does not take 2 parameters, instead takes 3. To make things simpler, use
putenv()