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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:26:10+00:00 2026-06-13T02:26:10+00:00

I was testing with c language today and I made two small c files

  • 0

I was testing with c language today and I made two small c files

main.c

#include<conio.h>
void testing();
int main()
{
    testing();
    getch();
    return 0;
}

testing.c

#include <stdio.h>

void testing()
{
    char ch;
    printf("Hello Testing\n");
    do{
        printf("Enter Character : ");
        ch=getchar();
        printf("You Entered : %c\n",ch);
        testing();
        }while(ch!='N');
}

The problem I am facing is it read one character from user and then it loop twice and I don’t know why

output
Hello Testing
Enter Character : k //(i entered k)
You Entered : k

Hello Testing// why this is displayed twice??
Enter Character : You Entered :// i don't press any key and it moves to next iteration

Hello Testing
Enter Character : // here i can enter character again and it happens again twice

I have complied it on Visual Studio 2012.

  • 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-13T02:26:12+00:00Added an answer on June 13, 2026 at 2:26 am

    Because getchar() leaves a newline character in the input buffer. You can use another getchar() to eat the newline.

    ch=getchar();
    getchar();
    

    Or use scanf to eat leading whitespaces:

    scanf(" %c", &ch);
    

    This way all the previous \n will be ignored.

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

Sidebar

Related Questions

I'm testing my app on the iOS simulator. I have two files of Localizable.strings
okay on our testing server the language works fine whetter your click it twice
I'm testing Java's i18n features and have a problem, I can't load the language
I'm creating script for automated testing of financial application. Using VbScript as language. Need
I'm making a small language that is very similar to hlsl but supports only
I'm using Selenium Webdriver on Visual Studio C# language. Nunit is the testing driver.
I was wondering how PCRE detects word characters from whatever language. I was testing
For purposes of testing compression, I need to be able to create large files,
I'm like to use one testing language (assertions and matchers) to do both unit
After testing a small site that I built for my school in Firefox, SeaMonkey,

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.