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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:39:16+00:00 2026-06-10T05:39:16+00:00

EDIT: I had to add a getchar(); after scanf(%i, &choice); now it asks only

  • 0

EDIT: I had to add a getchar(); after scanf(“%i”, &choice); now it asks only once!

Apparently its the case switch that’s causing it to output twice. If I call the function outside the case switch it ouputs 1, but if I called it inside the switch it outputs twice

What is causing this? I suspect the scanf choice?

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

        void test();
        void choose();
        int main(void)
        {   
//if i call here its fine
            test();
            choose();
            return 0; 
        }

        void choose()
        {
            int choice;

            do
            {
                printf("1 - Testing if double ask\n");
                printf("2 - Exit\n");
                printf("Please enter your choice: ");       
                scanf("%i", &choice);

                switch(choice)
                {//but pressing 1 here asks twice?
                    case 1:         
                        test();
                        break;
                    default:
                        if(choice !=2)
                            printf("Input Not Recognized!\n");
                        break;          
                }
            }
            while(choice !=2);
            if(choice == 2)
                printf("Ciao!");
        }
        void test()
        {
printf("HELLO");
                char *name = malloc (256);

                do      
                {
                    printf("Would you like to continue (y/n)\n");
                    fgets(name, 256, stdin);
                }
                while(strncmp(name, "n", 1) != 0);
                free (name);
        }
  • 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-10T05:39:18+00:00Added an answer on June 10, 2026 at 5:39 am

    First: you can’t compare C strings with the comparison operators != and ==. You’ll need to use strcmp for this.

    Furthermore I think you’ll find a do { ... } while loop more useful in this case. You’re checking name once before the user has had a chance to add any input.

    The next thing to be aware of is that fgets will retain the newline in your input, so you’ll need to address this in your usage of strcmp.

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

Sidebar

Related Questions

I had to add a column on a text file (edit with Notepad++ on
EDIT: My mistake was that I had a go after the first select statement
I had gridview whch bind datasource and I add edit command to gridview to
I lately had the problem of creating add and edit dialogs for my wpf
EDIT: I had made a mistake during the debugging session that lead me to
Answer solved in edit below I had this piece of code Dictionary<Merchant, int> remaingCards
I posted another one on this,, but i had to edit it really much...
Edit: Turns out I just had some values -switched-. I'm working with OpenGL and
EDIT: I was an idiot. I simply had an image that was vertically long,
I had a file I needed to edit in my .gitignore file. I edited

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.