如何在C中将数字更改为变量?

use*_*361 3 c variables execl

我想知道如何在C中替换变量的值.

execl ("/bin/cat","cat","/proc/30828/status", (char *)0 );
Run Code Online (Sandbox Code Playgroud)

我希望能够将"30828"更改为变量,因为此值不固定.我想知道是否可以在SHELL中做一些你能做到的事情.例如在shell中你可以这样做:

K=`ls -lis $i`
echo $K
Run Code Online (Sandbox Code Playgroud)

Bar*_*mar 5

用于snprintf()将PID替换为字符串变量:

char statusfile[30];
sprintf(statusfile, sizeof statusfile, "/proc/%d/status", pid);
execl("/bin/cat","cat",statusfile, (char *)0 );
Run Code Online (Sandbox Code Playgroud)