在我的程序中,我想使用命名管道“pipeselect”将我的switch case值发送到另一个进程。我在管道中写入数字并在另一个程序中读取数字。但是当我运行问题时,当我输入案例值时它无法显示任何内容。我怎么能这样做?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
char pipeselect[] = "/tmp/pipeselect";
char bufs[2];
int fds;
int select1;
/* Pipe Creation */
if (access(pipeselect, F_OK) == -1)
{
fds = mkfifo(pipeselect, 0700);
if (fds != 0)
{
printf("Pipe creation error\n");
exit(1);
}
}
printf("1. Option 1\n");
printf("2. Option 2\n");
printf("Please select an option: ");
scanf("%d", &select1);
int i = select1;
switch (i)
{
case 1:
if ((fds = open(pipeselect, O_WRONLY)) < 0)
{
printf("Pipe open error\n");
exit(1);
}
write(fds, bufs, i);
close(fds);
printf("Option 1 is selected\n");
break;
case 2:
if ((fds = open(pipeselect, O_WRONLY)) < 0)
{
printf("Pipe open error\n");
exit(1);
}
write(fds, bufs, i);
close(fds);
printf("Option 2 is selected\n");
break;
default:
printf("Wrong Input!\n");
break;
unlink(pipeselect);
exit(0);
}
}
答案 0 :(得分:0)
你可能需要像这样使用Route::group(['prefix' => 'api', 'middleware' => 'cors'], function()
{
Route::resource('authenticate', 'AuthenticateController', ['only' => ['index']]);
Route::post('authenticate', 'AuthenticateController@authenticate');
});
:
write
顺便说一句,你可以像这样缩小你的代码范围:
bufs[0] = i; // put value entered by user into buffer
write(fds, bufs, 1); // write 1 byte from the buffer