「ls」または「ls -l」のようなものを取り、それを実行する単純なシェルを作成しようとしています。
これが私のコードです:
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
void execute(char **argv)
{
int status;
int pid = fork();
if ((pid = fork()) <0)
{
perror("Can't fork a child process\n");
exit(EXIT_FAILURE);
}
if (pid==0)
{
execvp(argv[0],argv);
perror("error");
}
else
{
while(wait(&status)!=pid)
;
}
}
int main (int argc, char **argv)
{
char args[256];
while (1)
{
printf("shell>");
fgets(args,256,stdin);
if (strcmp(argv[0], "exit")==0)
exit(EXIT_FAILURE);
execute(args);
}
}
次のエラーが表示されます。
basic_shell.c: In function ‘main’:
basic_shell.c:42: warning: passing argument 1 of ‘execute’ from incompatible pointer type
basic_shell.c:8: note: expected ‘char **’ but argument is of type ‘char *’
実行関数に引数を正しく渡す方法について、いくつかの指針を教えてください。