-1

ちょっと私はCの初心者プログラマーで、プログラムで発生するこれらのエラーを理解していません。誰かが私のコードの何が問題なのか、それを修正する方法を教えてください。私はこれを学びたいと思っています。どんな助けにも感謝します。

コンパイラ メッセージ:

gcc project1shell.c
project1shell.c: In function ‘main’:
project1shell.c:55:8: warning: passing argument 1 of ‘hello’ makes pointer from integer without a cast [enabled by default]
project1shell.c:16:6: note: expected ‘char *’ but argument is of type ‘char’
project1shell.c:62:8: warning: passing argument 1 of ‘forkk’ makes pointer from integer     without a cast [enabled by default]
project1shell.c:18:6: note: expected ‘char *’ but argument is of type ‘char’

私のコード:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

#define CHILD 0
#define SIZE 256

char hello(char command[SIZE]);
void forkk(char command[SIZE]);
void exitt(char command[SIZE]);

/////////////////////////////

int main(void) {

/* variable delcarations */
char command[SIZE]="";
char buffer[SIZE]="";

/////////////////////////////

    /**** prompt the user with the program ****/
    printf("*** Welcome to LJ's Shell! ***\n\n");

    /**** implements exit and commands ****/
    while(1) {
       if (strcmp(command, "exit") == 0) {
          break;
       }
       hello(command[SIZE]);

       //prompt(command[SIZE], buffer[SIZE]);
       printf("nshell:~$ ");
       fgets(buffer, sizeof(buffer), stdin);
       sscanf(buffer, "%s", command);

       forkk(command[SIZE]);
    }

}


///////// Functions //////////

/************ fork process **************/
void forkk(char command[SIZE]) {
    int pid = 0;
    int childvalue = 0;

    if (strcmp(command, "fork") == 0) {

       pid = fork();

       if (pid != CHILD) {   /* this is the parent */
           printf("I am the parent.  Ready to wait on the child.\n");
           pid = waitpid(-1, &childvalue, 0);
           printf("Child %d returned a value of %x in hex.\n", pid, childvalue);
           return;
       }
       else {  /* this is the child */
           printf("I am the child.\n");
           exit(2);
       }
    }
}

/***************** exit *******************/

void exitt(char command[SIZE]) {
    if (strcmp(command, "exit") == 0) {
       exit(0);
    }
}

/************* Hello Test ****************/
char hello(char command[SIZE]) {
    if (strcmp(command, "hello") == 0) {
    printf("Hello there!\n");
    //reset command back to ""
    }
}
4

2 に答える 2