クライアントからサーバーに送信されたコマンドを解釈するプログラムを作成しようとしています。私の問題は、コマンドの最初の単語しか読めないことです。
dict.h
typedef struct
{
pid_t pid_cliente;
int status;
char command[TAM_MAX];
char secure[TAM_MAX];
char password[TAM_MAX];
int client_type;
} request;
クライアント側
printf("[ADMIN]: ");
scanf("%s[^\n]", buffer); //reads command
printf("Sending -> '%s'\n", buffer);
strcpy(request.command, buffer, MAX_SIZE-1) //MAX_SIZE = 50
write(server_fifo, & request, sizeof(request));
サーバ側
read_res = read(server_fifo, & request, sizeof(request));
if (read_res < sizeof(request))
{
if (!strncasecmp("exit",(char *) & request,4)) return;
else
{
fprintf(stderr, "\nMessage Error!");
return;
}
}
token = strtok(request.command, " "); //reads command
printf("Command -> '%s'\n", token)
..
interprets wich command to do
..
token = strtok(NULL, " "); //reads command argument
printf("Argument -> '%s'\n", token);
入力:
addcity lisbon
出力:
Sending -> addcity
Sending -> lisbon
Command -> addcity
Argument -> (NULL)