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 4066028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:05:09+00:00 2026-05-20T16:05:09+00:00

I read more threads about scanf and I found some answers bot none helped

  • 0

I read more threads about scanf and I found some answers bot none helped me:

while(!comanda){
    int tmp;
    if (scanf("%d", &tmp) == 0)
        getchar();
    else{
        comanda = tmp;
        fprintf(stdout,"%d",&comanda);
        fflush(stdout);}
    }
}

The problem is that after this lines of code get executed, nothing happens. After this I have a check on “comanda” which does not execute.

  • 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-05-20T16:05:10+00:00Added an answer on May 20, 2026 at 4:05 pm

    One of the problems with scanf and all of the formatted input functions is that terminals tend to operate in line mode or cooked mode and the API is designed for raw mode. In other words, scanf implementations generally will not return until a line feed is encountered. The input is buffered and future calls to scanf will consume the buffered line. Consider the following simple program:

    #include <stdio.h>
    
    int main() {
        int a_number;
        printf("Enter a number: ");
        fflush(stdout);
        while (scanf("%d", &a_number) != EOF) {
            printf("you entered %d\n", a_number);
            printf("Enter another number: ");
            fflush(stdout);
        }
        return 0;
    }
    

    You can enter multiple numbers before pressing return. Here is an example of running this program.

    bash$ gcc foo.c
    bash$ ./a.out
    Enter a number: 1 2 3 4 5 6 7 8 9 10<Return>
    you entered 1
    Enter another number: you entered 2
    Enter another number: you entered 3
    Enter another number: you entered 4
    Enter another number: you entered 5
    Enter another number: you entered 6
    Enter another number: you entered 7
    Enter another number: you entered 8
    Enter another number: you entered 9
    Enter another number: you entered 10
    Enter another number: <Ctrl+D>bash$ 
    bash$
    

    Each call to scanf read a single number from the input stream but the first call did not return until after I pressed return. The remaining calls returned immediately without blocking for more input because the input stream was buffered and it could read another integer from the stream.

    The alternatives to this are to use fgets and processing entire lines of data at one time or using the terminal interface to disable “canonical input processing”. Most people use fgets since the terminal interface section of POSIX is not implemented under Windows.

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

Sidebar

Related Questions

I have found C++ FQA Lite very edificatory and would like to read more
I have quickly read (and will read with more care soon) the article of
which one of the two is more spread? I want to read out the
Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service
I read an interesting DailyWTF post today, Out of All The Possible Answers... and
I read this PHP RegEx page , but either I'm missing something, misreading something,
I read somewhere once that the modulus operator is inefficient on small embedded devices
I read the Git manual, FAQ, Git - SVN crash course, etc. and they
Please read the whole question. I'm not looking for an approach to managing multi-lingual
I read in this article that a company has created a software capable of

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.