日期:2014-05-16  浏览次数:20794 次

请问如何在C语言中嵌入的shell脚本中获得C语言程序中定义的某个变量
RT  
比如我在C程序中定于了   a变量。
如何在我嵌入的shell脚本中使用这个变量
例子:
system(“file   -b   a”);
这样显然是不行的。
有高人指点吗?

------解决方案--------------------
#include <stdio.h>

int main(void)
{
char s[81];
char a[] = "demo.txt ";
snprintf(s, 80, "file -b %s ", a);
system(s);
return 0;
}