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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:07:31+00:00 2026-05-21T11:07:31+00:00

The code below is supposed to prompt the user, step-by-step, for information. Currently, however,

  • 0

The code below is supposed to prompt the user, step-by-step, for information. Currently, however, it waits for information and then display the prompts as well as the provided content. Can anyone explain why this is happening? Thanks.

contacts.h file

struct contacts {
    int phone_number;
    char first_name[11], last_name[11];
};

rolodex.c file

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "contacts.h"

int main(int argc, char* argv[]) {
    struct contacts* c = (struct contacts*) malloc(sizeof(struct contacts));
    if (c == 0) {
        return 1;
    }
    set_first_name(c);
    set_last_name(c);
    set_phone_number(c);
    display_contact(c);
}

int set_first_name(struct contacts* c) {
    puts("\nWhat is your first name? ");
    gets(c->first_name);
    return 0;
}

int set_last_name(struct contacts* c) {
    puts("\nWhat is your last name? ");
    gets(c->last_name);
    return 0;
}

int set_phone_number(struct contacts* c) {
    printf("\nWhat is your phone number? ");
    scanf(" %d", &c->phone_number);
    return 0;
}

int display_contact(struct contacts* c) {
    printf("\nName: %s %s Number: %d", c->first_name, c->last_name, c->phone_number);
    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-05-21T11:07:32+00:00Added an answer on May 21, 2026 at 11:07 am

    The standard output stream is line buffered by default. That means that output shorter than a whole line is not guaranteed to be seen before execution continues with other statements.

    Either end your output with a '\n' or fflush(stdout).

    Example
    EDITED: the previous example used puts which already ends the output with a '\n'

    int set_phone_number(struct contacts* c) {
        printf("\nWhat is your phone number?\n"); /* \n at end of output */
        scanf(" %d", &c->phone_number);
        return 0;
    }
    

    or

    int set_phone_number(struct contacts* c) {
        printf("\nWhat is your phone number? ");
        fflush(stdout);                           /* force output */
        scanf(" %d", &c->phone_number);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my code below is supposed to display N lines per inch. instead i get
My code below is supposed to display each question ($_POST[questionText]). For each question, it
Code below is working well as long as I have class ClassSameAssembly in same
So below I have a code in C++ that is supposed to invert the
Apple says in the Safari HTML reference that the below code is supposed to
The code below is supposed to get the next record when a button is
The code below partially works. Its supposed to return all the tables in the
The code below is supposed to show a stack of three list boxes, each
The code below is supposed to check whether the name already exists in the
The code below is supposed to initiate CSS based on if($row[datesubmitted] > $livetime){ .

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.