Search
 
SCRIPT & CODE EXAMPLE
 

C

fifo in c

// C program to implement one side of FIFO
// This side writes first, then reads
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    int fd;

    // FIFO file path
    char * myfifo = "/tmp/myfifo";

    // Creating the named file(FIFO)
    // mkfifo(<pathname>, <permission>)
    mkfifo(myfifo, 0666);

    char arr1[80], arr2[80];
    while (1)
    {
        // Open FIFO for write only
        fd = open(myfifo, O_WRONLY);

        // Take an input arr2ing from user.
        // 80 is maximum length
        fgets(arr2, 80, stdin);

        // Write the input arr2ing on FIFO
        // and close it
        write(fd, arr2, strlen(arr2)+1);
        close(fd);

        // Open FIFO for Read only
        fd = open(myfifo, O_RDONLY);

        // Read from FIFO
        read(fd, arr1, sizeof(arr1));

        // Print the read message
        printf("User2: %s
", arr1);
        close(fd);
    }
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: atoi string to int 
C :: hash function in c 
C :: rust unit test display 
C :: c function definition 
C :: Increment & Decrement Operator in C language 
C :: stack pop 
C :: C Syntax of goto Statement 
C :: C How to define a union? 
C :: deleting a word with copy fuction c code 
C :: len of str vbs 
C :: voide means in c 
C :: how to print chicken in c 
C :: powershell some fonts like #include are dissapearing 
C :: change base int in c 
C :: findtotalcurtain 
C :: solidity signature r s v 
C :: convert c to python online 
C :: how to limit tiktok on mikrotik 
C :: unigine 
C :: Uri/beecrowd problem no - 1099 solution in C 
C :: write a c program to find out ncr factor of given number 
C :: clarity ppm jasper domain commands 
C :: How to scale all columns in dataframe in R- Method 2? 
C :: anticonstitutionnellement 
C :: /usr/bin/mandb: fopen /var/cache/man/7935: Permission denied 
C :: gsl matrix invert 
C :: c ternary operator 
C :: how to find the elements in array c coding 
Dart :: flutter remove debug badge 
Dart :: flutter label alignment top 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =