壳体解释器错误

  • 本文关键字:错误 解释器 c
  • 更新时间 :
  • 英文 :


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

#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 foundn");
          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]

你有没有试过包括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.

最新更新