Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:40:25+00:00 2026-06-02T17:40:25+00:00

This is a small C program concerning pipes and processes, The Father process will

  • 0

This is a small C program concerning pipes and processes, The Father process will create 2 child processes, the first will read the numbers out of a chain, the second will read the letters. I started by asking for the WORD, I didnt add protection this is just a test, so lets say about 20 letters, then the father process will write the numbers in the first pipe, and the letters in the second pipe, then he will create a child using fork(), if he’s the child , he will read the numbers from the first pipe, if he’s the father, then he will create another child, to read the letters.

# include <stdio.h>
# include <unistd.h>
# include <string.h>
# include <fcntl.h>

main()
{
    printf("I am the father, I will create 2 sons, the first will read the numbers , the second will read the letters\n");
    char * word;
    printf("please type the word: \n");
    scanf("%s",word);
    printf("Now 2 pipes will be created\n");
    int fd1[2];
    int fd2[2];
    pipe(fd1); pipe(fd2);
    printf("Now the father will write numbers in the first pipe, and letters in the second\n");
    int i;
    char numbers[20]; int j=0;
    char caracters[20]; int k=0;
    for (i=0;i<20;i++)
    {
        if(word[i]>='0' && word[i]<='9') //if number
        {
            close(fd1[0]); //closing reading
            write(fd1[1],word[i],2);

        }
        else
        {
            close(fd2[0]);  
            write(fd2[1],word[i],2);
        }

    }
    printf("The father has wrote in the 2 pipes, now its time for the sons\n");
    int f=fork();
    if(f==0) //first son
    {
        for(i=0;i<20;i++) {         
            close(fd1[1]); //closing writing
            read(fd1[0],numbers[j],strlen(numbers[j])+1);
            j++;

        }
        printf("first son read everything, he got %d Numbers\n", j);
    }
    else
    {
        f=fork();
        if(f==0)
        {
            for(i=0;i<20;i++) {         
            close(fd2[1]); //closing writing
            read(fd2[0],caracters[k],strlen(caracters[k])+1);
            k++;

        }   
        printf("second son read everything, he got %d caracters\n", j);
    }
}

after compiling :

In function 'main':
Line 25: warning: passing argument 2 of 'write' makes pointer from integer without a cast
Line 31: warning: passing argument 2 of 'write' makes pointer from integer without a cast
Line 41: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
Line 41: warning: passing argument 2 of 'read' makes pointer from integer without a cast
Line 54: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
Line 54: warning: passing argument 2 of 'read' makes pointer from integer without a cast
Line 60: error: expected declaration or statement at end of input
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:40:27+00:00Added an answer on June 2, 2026 at 5:40 pm

    The prototype of write and read are

    ssize_t write(int fd, const void *buf, size_t count);
    
    ssize_t read(int fd, void *buf, size_t count);
    

    Argument 2 to write/read should be a pointer. But what you are sending is a character (which is an integer in fact) word[i] and numbers[i]

    Same problem even with your strlen

    Also, declare word as an array instead of just a pointer. Else you would be writing to wherever random location the pointer is pointing to. Or if you wanna keep it as a pointer, malloc some memory for it.

    After all this, just pass word, numbers instead of numbers[j] or words[i] to your functions which are complaining

    EDIT: Also your last for statement for(i=0;i<20;i++) lacks a closing brace and hence the Line 60: error: expected declaration or statement at end of input error

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this small program and it needs to create a small .txt file
I got this code inside a small program to read a file: #ifdef WIN32
I'm trying to create a small program to run on a centralized device. This
Many books/articles I've read on this topic, as well as a small program I
How can I include foo() function of foo.c in this small program (sorry for
I wrote this small C++ program and built it(Release) #include<iostream> int main(){ std::cout<<Hello World;
this is a small program using Java Scanner which reads a file of double
I'm running this small C# test program launched from a pre-commit batch file private
I'm building this small java applet in which I need a JPanel which will
Trying to write this small program to help me in my Stats class, everything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.