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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:10:29+00:00 2026-06-14T14:10:29+00:00

A very simple question. Why scanf is skipped in the first while loop. I

  • 0

A very simple question. Why scanf is skipped in the first while loop.
I have tried it by using getchar() and the result is same. getchar is skipped.

If you guys dont understand what I’m talking about you can tried compile it and you guys will understand what i’m asking about.

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

typedef struct rec{
    int num;
    char pref[16];
    float point;
    struct rec* next;
}rec;

void dataInput(float*,char*);
rec* insertNode(rec*);

int main(){

    int i=1;
    rec* entr,*pt = NULL;
    entr = (rec*) malloc(sizeof(rec));
    entr->num = i;
    dataInput(&entr->point,entr->pref);
    entr->next = NULL;
    char key;
    i++;

    while(1){

        printf("Continue ? If YES press 'y',or NO press 'n'\n");
        key = getchar();
        if(key == 'n')break;
        else if(key == 'y'){
            if(!pt){
                pt = insertNode(entr);
            }else{
                pt = insertNode(pt);
            }
            dataInput(&pt->point,pt->pref);
            pt->num = i;
            i++;
            continue;
        }else{
            printf("Wrong key! Please Press again! \n");
        }

    }

    pt = entr;
    while(pt){

        printf("num : %d, pref :  %s, point: %.1f\n",
                pt->num,
                pt->pref,
                pt->point);
        pt = pt->next;
    }

    getchar();
    getchar();
    return 0;
}

void dataInput(float* point,char* pref){

    printf("Input Point\t : ");
    scanf("%f",point);

    printf("Input Pref\t : ");
    scanf("%s",pref);
}

rec* insertNode(rec* current){
    rec* newnode = (rec*)malloc(sizeof(rec));
    current->next = newnode;
    newnode->next = NULL;
    return newnode;
}
  • 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-14T14:10:30+00:00Added an answer on June 14, 2026 at 2:10 pm

    It’s because scanf will leave a '\n' (endline) symbol in the input buffer. This symbol will be consumed by getchar at the first iteration of this while(1) loop.

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

Sidebar

Related Questions

I have a very simple code segment where there is a do while loop
Very simple question... I have an array of pixels, how do I display them
Very simple question, but I want to start using a consistent naming convention for
A very simple question. I have a html page which is divided into three
Very simple question, hopefully. So, in Python you can split up strings using indices
Very simple question I am sure. I have a file called ACLReader.vbs which I
A very simple question: I am writing and running my R scripts using a
very simple question: I have admin site in my web project. So, how can
Very simple question: suppose I have the following js/jquery code doSomething(); $.get(url, callback); doSomethingElse();
A very simple question. I have a .war(~40MB) file to be run on JBoss.

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.