简体   繁体   中英

Compile and run a C file from another C program without using command line

I have two C programs:

Main.c

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

int main()
{

    system("gcc x.c -o x");
    system("x.exe");
    return 0;

}

xc

#include <stdio.h>

int main() {


  printf("hello world!");

  return 0;
}

From Main.c I need to compile and run xc without using the command line. I've tried this but the code didn't work. Thanks

此函数调用将编译您的文件并在一行中运行它:

system("gcc x.c -o x && x.exe");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM