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

  • Home
  • SEARCH
  • 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 8977325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:20:41+00:00 2026-06-15T19:20:41+00:00

I have been stuck with this problem on and off since last night and

  • 0

I have been stuck with this problem on and off since last night and I’m hoping a second fresh pair of eyes will help.

The problem, if an invalid input is entered in the userIn function (anything that isn’t a number between 1-99) the test printf at the end of the while loop in main prints “ERR = 1”, the while loops and userIn is called again. So far so good, but when a valid input is entered the test printf at the end of the while loop prints “ERR = 0” and then the program hangs. The test printf saying “HELLO” never gets printed.

Any suggestions as to why are most welcome.

The code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

void userIn (int *x)
    {
    char b;
    printf("Please enter a new value for Vm: ");
    scanf(" %i",x);
    while (((b=getchar())!='\n')&&(b!=EOF));
    return; 
    }
int main (void)
    {
    int  fd, x, err;
    char *npipe = "/tmp/fms",
         input[3];
    struct stat info;
    printf("\n");

    //get user input
    err = 1;
    while (err)
        {
        userIn(&x);
        if (x > 0 && x < 100) err = 0;
        //else printf("\033[1A\033[K");

        printf("ERR = %i\n",err);//TEST PRINTF
        }
    printf("HELLO");//TEST PRINTF

    //if pipe exists
    if ( (!lstat(npipe,&info)) && (S_ISFIFO(info.st_mode)) )
        {
        sprintf(input,"%i",x);
        //write user input to named pipe created by 'parent.c'
        fd = open(npipe, O_WRONLY);
        write(fd, input, sizeof(input));
        close(fd);
        }
    else printf("\033[0;31mNamed pipe doesn't exist, %i not passed.\n\n\033[0m",x);
    return 0;
    }
  • 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-15T19:20:43+00:00Added an answer on June 15, 2026 at 7:20 pm

    If I run your code on my system the output looks like this:

    Please enter a new value for Vm: 101
    ERR = 1
    Please enter a new value for Vm: 1
    ERR = 0
    HELLONamed pipe doesn't exist, 1 not passed.
    

    That is, the loop exits exactly when you think it should. Of course, the code then exits immediately because /tmp/fms does not exist on my system.

    However, if I create /tmp/fms, then I see:

    Please enter a new value for Vm: 1
    ERR = 0
    

    …and no additional output. This is because the output from the printf statement is buffered, and the write to the named pipe is blocking, so the output never gets flushed. Adding a \n to your printf will probably display it as you expect.

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

Sidebar

Related Questions

Hope to get solution to this problem. I have been stuck on it since
I have been stuck on this problem for awhile now, and I was hoping
I have been stuck on this problem for a very long time. I have
I have been stuck in this problem for two weeks, I hope someone could
I'm very new to AS3 and I have been stuck with this problem for
I have been stuck on this problem for many hours, but I have a
I have been stuck with this problem for a while now. I know that
I have been stuck on this for a while now and I cannot seem
I have been stuck on this for days, and was wondering if anyone had
I have been stuck on this for a while. i have tried and I

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.