-1

有人可以帮助这个简单的程序提示用户输入命令吗?

#include "unistd.h"
#include "stdio.h"


 int main(){
      char command[80];
      while (putchar('#'), gets(command)) {
        if (fork()){
          wait(0); /* Parent */
    }
        else { /* Child */
          execlp(command, command, 0);
          printf("command not found\n");
          exit(1);
        }
      }

}

给出的命令:gcc system.c -o system.exe

错误如下:

system.c: In function ‘main’:

system.c:12:7: warning: missing sentinel in function call [-Wformat]

system.c:14:7: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
4

1 回答 1

2

您是否尝试过包含 unistd.h 和 stdio.h ?

哦,顺便说一下,从 gets() 的手册中:

Never  use gets().  Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because
gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use.  It has been used to break computer
security.  Use fgets() instead.
于 2012-11-24T10:58:59.883 回答