How it works...

Let's assume we have defined a string called str of size 255. We will invoke the mkfifo function to create a new FIFO special file. We will create the FIFO special file with the name FIFOPipe with read and write permissions for owner, group, and others.

We will open this FIFO special file in write-only mode by invoking the open function. Then, we will assign the file descriptor of the opened FIFO special file to the fw variable. You will be prompted to enter the text that is going to be written into the file. The text you enter will be assigned to the str variable, which in turn will be written into the special FIFO file when you invoke the write function. Finally, close the FIFO special file.

Let's use GCC to compile the writefifo.c program, as follows:

$ gcc writefifo.c -o writefifo

If you get no errors or warnings, this means that the writefifo.c program has compiled into an executable file, writefifo.exe. Let's run this executable file:

$ ./writefifo
Enter text: This is a named pipe demo example called FIFO

If your program does not prompts for the string that means it is waiting for the other end of the FIFO to open. That is, you need to run the next recipe, Reading data from a FIFO, on the second Terminal screen. Please press Alt+F2 on Cygwin to open the next terminal screeen.

Now, let's check out the other part of this recipe.