将一个C程序的输出转换为另一个C程序中的变量

Ron*_*nin 5 c c++ windows variables

我有2个C程序.说一个是program-1.c

int main(){
printf("hello world");
}
Run Code Online (Sandbox Code Playgroud)

现在在第二个代码命名中program-2.c,我想将第一个代码的输出变成一个变量,这样我就可以将输出"hello world"输入到第二个C代码中的变量中.

我怎样才能做到这一点?

Mat*_*Mat 11

您可以使用此popen功能:

FILE* proc1 = popen("./program1", "r");
// Usual error handling code goes here
// use the usual FILE* read functions
pclose(proc1);
Run Code Online (Sandbox Code Playgroud)