首页 > 技术文章 > c语言中,为什么以下程序直接按”Enter“也就是回车程序不结束?

yanglai 2017-05-19 19:51 原文

 1 /*************************************************************************
 2     > File Name: system.c
 3     > Author: Mr.Yang
 4     > Purpose:演示system()函数
 5     > Created Time: 2017年05月19日 星期五 19时29分17秒
 6  ************************************************************************/
 7 
 8 #include <stdio.h>
 9 #include <stdlib.h>
10 
11 char input[40];
12 
13 int main(void)
14 {
15         while(1)
16         {
17                 printf("Input the desire system command,blank to exit:");
18                 fgets(input,40,stdin);
19                 if(input[0] == '\0')//检测是否是空字符,如果是,直接退出程序,但在linux上运行不退出?
20                 {
21                         exit(0);
22                 }
23                 else
24                 {
25                         system(input);
26                 }
27         }
28 
29         return 0;
30 }

 

推荐阅读