-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 に答える