mac下c语言里面无法运行system语句

输出:
sh: color: command not found

wa wa wash: pause: command not found

Program ended with exit code: 0

编辑器用的是xcode

system函数是可以用的,但是[划重点]

在Mac系统里system函数使用的是Terminal命令

所以,这个命令在Mac系统里不存在


通俗点说:你在程序里使用“system("cls")”就等于在Terminal中输入“cls

但是在Terminal命令中没有color和wa命令,所以就会出现“command not found”[中文:命令未找到]错误,如果需要清屏,请使用“system("clear")”[这里说明一下,Mac清屏是很多个'\n']


附录:

外国的讨论(关于Mac system("pause"))

I haven't heard that Linux has this command. It should not. But there is no doubt that the system function can be used. If you don't mind changing from pressing any key to pressing the space bar, you can output "press the space bar to continue", and then use a while loop until getchar() returns the value "\n". If you use Windows system, you can use the getch() function in the conio.h library, so you can input without '\ n', but you can use the "system (" pause ")" function directly if you use Windows system.

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-04-05
您好,百度百科:system
system()会调用fork()产生子进程,由子进程来调用/bin/sh-c
string来执行参数string字符串所代表的命令,此命令执行完后随即返回原调用的进程。在调用system()期间SIGCHLD
信号会被暂时搁置,SIGINT和SIGQUIT 信号则会被忽略。
#include"stdio.h"
int main()
{ char A,B,C,D,j;
printf("请输入你的证件类型(A,B,C,D)");
scanf("%c",&j);
if(j==A)//错误在这里,A是字符类型,其比较方法应该是j=='A',下同
printf("A类");
else if(j==B)
printf("B类");
else if(j==C)
printf("C类");
else if(j==D)
printf("D类");

return 0;
}本回答被网友采纳
相似回答