How can I change a number to a variable in C?
I would like to know how to substitute the value of a variable in C.
execl ("/bin/cat","cat","/proc/30828/status", (char *)0 );
I would like to be able to change "30828" to a variable because that value is not fixed. I am wondering if it is possible to do something like SHELL where you can do it. For example, in a shell, you can:
K=`ls -lis $i`
echo $K
+3
user3671361
source
to share
1 answer
Use snprintf()
to replace PID with a string variable:
char statusfile[30];
sprintf(statusfile, sizeof statusfile, "/proc/%d/status", pid);
execl("/bin/cat","cat",statusfile, (char *)0 );
+5
Barmar
source
to share