编程语言:C
我想把我的程序放在一个由命令行参数控制的无限循环中。
我的意思是,除非我输入“退出”,否则它应该根据我输入的参数继续执行。
发布于 2011-11-04 22:12:06
发布于 2011-11-04 22:29:01
试试这个:
#include <stdio.h>
int main(int argc,char *argv[]);
{
char cmd = '\0';
char quit = 0;
while(quit==0) {
cmd = fgetc(stdin);
switch(cmd) {
case 'q':
{
quit =1;
break;
}
// process other cases.
}
}
fprintf(stdout,"Quiting\n");
}发布于 2011-11-19 01:49:25
如果我没记错的话,您可以在stdlib.h中使用以下函数: system(),其中语法如下:
int system(const char \*command);在这里,您可以将任何shell命令作为字符串参数传递
https://stackoverflow.com/questions/8010596
复制相似问题