关于在C语言里使用SYSTEM的问题
有一个问题,就是在,在C语言里运行一个system("TCC -c **");这个**怎么改为自己想要的名字?比如改为aa.c。在批处理中我知道,就是用%1来处理,但是在C语言中不知道怎么做,可以同一个字符数组,但是存完了想要存的名字之后怎么加在tcc -c 的后面并且正常运行??百度都不知道怎么搜索,到这里求助来了。。。
[解决办法]
SYSTEM其实和批处理差不多的。
The system function executes an internal operating system command, or an .EXE, .COM (.CMD in Windows NT) or .BAT file from within a C program rather than from the command line.
The system function finds the command interpreter, which is typically CMD.EXE in the Windows NT operating system or COMMAND.COM in Windows. The system function then passes the argument string to the command interpreter.
[解决办法]
用sprintf组字符串,组好后传给system。
char str[256] = {0};
char cmd[256] = {0};
fgets(str, sizeof(str) - 1, stdin);
sprintf(cmd, "tcc -c %s", str);
system(cmd);