在C语言中,如何向以前使用system()调用的程序提供输入?

在C语言中,如何向以前使用system()调用的程序提供输入?,c,C,我现在想让一个名为with system的程序,在输入不是参数的情况下接受输入。由于可能有点不清楚,我将用一个简单的例子来说明我的问题 假设我们有两个程序,askname.c和call.c askname.c #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { char name[10]; printf("What is your name ?

我现在想让一个名为with system的程序,在输入不是参数的情况下接受输入。由于可能有点不清楚,我将用一个简单的例子来说明我的问题

假设我们有两个程序,askname.c和call.c

askname.c

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
     char name[10];
     printf("What is your name ? ");
     fgets(name, 10, stdin);
     printf("So you are %s \n", name);
 
     return 0;
}
在这之后,我会用call.c给askname打电话

#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]){
char* foo ="test";
system("./askname");
//somehow make askname receive foo to display "So you are test"
return 0;
}

知道如何继续吗?

你不知道。你用别的东西。也许是波本

FILE *fp = popen("./askname", "w");
fprintf(fp, "%s\n", foo);