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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:35:11+00:00 2026-05-28T00:35:11+00:00

I have often seen cases where in a series of printf statements that ask

  • 0

I have often seen cases where in a series of printf statements that ask for an input, certain
statements do not accept an input, i.e.

printf_statement1:

printf_statement2: /*Enter input here*/

i.e. before the user enters an input for statement1, statement2 is printed, that allows the user to enter an input, and then repeats the same with statement3 & statement4.

What prompts such a case?

I encounterd this, but not any more, in:

 printf("\n\n\t\tName: ");
 scanf("%s", name); //initially used gets
 printf("\n\n\t\tType: ");     
 scanf("%c", &type);
 printf("\n\n\t\tAddress: ");      //initially used gets
 scanf("%s", address);
 printf("\n\n\t\tDate - of - Birth: ");
 scanf("%s", dob); //initially used gets

Output:

Name:
Type: I enter something!
Address:
Date - of - Birth: I enter something!
  • 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-28T00:35:11+00:00Added an answer on May 28, 2026 at 12:35 am

    Sometimes in cases like these, it is helpful to call fflush() on stdin before reading from it:

    char name[40+1];
    printf("\n\tName: ");
    fflush(stdin);
    scanf("%40s", name);
    

    Depending on the circumstances, there may be a newline in the input buffer that causes your first scanf to get skipped (given no input).

    Also note that you should specify the size of the buffer in scanf as to avoid buffer overflows.

    A format specifier for scanf looks like this:

    %[*][width][modifiers]type
    

    width: Specifies the maximum number of characters to be read in the current reading operation

    Thus, the %40s specifies that only 40 characters may be read in to the string. Note that the buffer is 41 characters, leaving room for the NULL terminator.

    Edit: Some sources (like this and this) say that you should avoid calling fflush(stdin) and it is incorrect. However, the Linux man page states:

    For input streams, fflush() discards any buffered data that has been fetched from the underlying file, but has not been consumed by the application.

    Conforming to C89, C99, POSIX.1-2001, POSIX.1-2008.
    The standards do not specify the behavior for input streams. Most other implementations behave the same as Linux.

    Additionally: MSDN says nothing about calling fflush(stdin) other than the following:

    If the stream is open for input, fflush clears the contents of the buffer.

    One would think that if calling fflush(stdin) was such a problem, one of the two largest sources of documentation on fflush would have mentioned this.

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

Sidebar

Related Questions

Browsing through some C++ questions I have often seen comments that a STL-friendly class
I have often seen Makefiles that start commands with an @ symbol to suppress
I have often seen the spinning gears OpenGL example ( I think originally done
I have often seen an init() within the constructor of AS3 classes, sometimes even
I have often PATHs for files which do not exist in my codes. I
I have often heard complaints against Java for not having unsigned data types. See
I often have to deal with XML documents that contain namespaced elements, but doesn't
I have found that I often have to implement some sort of a scheduler
I have often heard that using break s in Java is considered bad practice,
I've often seen line_item tables for orders or invoices that copy one or more

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.