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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:43:00+00:00 2026-06-04T19:43:00+00:00

In my program there is a minor problem. When I press 2 or 3

  • 0

In my program there is a minor problem.

When I press 2 or 3 or 4 it will display the properly but after that when I
press the a or b or c etc., it will display previous one result instead of print the Invalid option.

How can I fix this?

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

    typedef struct vehicle
    {
    char name[100];
    char lice_no[25];
    int vehicle_type;
    char cmpny_name[100];
    int menu_year;
     }record;

    int main(void)
    {
    int i,choice;
    FILE *fp1,*fp2;
    char oname[100];
    record det,det1;
    int recsize;
    char c;

    fp1 = fopen("record.dat" , "r+");
    if(fp1 == NULL)
    {
        fp1 = fopen("record.dat" , "w+");
        if(fp1 == NULL)
        {
            printf("error in opening file : \n");
            return -1;
        }
    }
    recsize = sizeof(det);

    do
    {
        printf("\t\"enter the choice\"\n");

        printf("1 : adding the record\n");
        printf("2 : delete the record\n");
        printf("3 : editing the record\n");
        printf("4 : display the record\n");
        printf("5 : exit the program\n");


        fflush(stdin);
        scanf("%d" , &choice);
        scanf("%c" , &c);

        switch(choice)
        {
            case 1 :
            {
                    printf("In this add logic\n")
                break;
            }
            case 2 :
            {
                printf("In this case delete logic\n");
                break;
            }
            case 3 :
            {
                printf("In this case edit logic\n");
                                break;
            }
            case 4 :
            {
                printf("display logic\n");
                break;
            }
            case 5 :
            {
                printf("exit logic\n");
                break;
            }
            default :
            {
                printf("\"Invalid option\"\n");
                break;
            }
        }
    }
    while(1);
    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-06-04T19:43:01+00:00Added an answer on June 4, 2026 at 7:43 pm

    It looks like you are getting the numbers into Choice, and the chars into c.
    but you are only using the Choice var in the switch, you are never checking the C var.

    So essentially, if you hit a letter it is storing it in the C var, and then using the old value in Choice again.

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

Sidebar

Related Questions

I have a program, and in that program there is some variables (username and
Is there a program to compare one folder and all subfolders to another folder
Is there any program code that can help me to pop up the virtual
there is a windows program that supports Regular Expression (or Dos Expression) for search
I know that there are no fixed rules about software version control but I
I want to write a Python program that makes PNG files. My big problem
I have the following problem, will try to describe it shortly. In my program
In a javascript program there is an array (gData) that contains objects. Each of
I am currently working on a VB.Net program where there are two parallel multiline
Is there a program which I can run like this: py2py.py < orig.py >

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.