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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:03:40+00:00 2026-05-16T02:03:40+00:00

In the code below in lesson2() i have used a password to enter the

  • 0

In the code below in lesson2() i have used a password to enter the function but when i enter the function it does not takes in the passord and says incorrect password.By not taking in the password,i mean to say that i have used gets but its waiting for me to input a password.please dont tell me not to use gets!

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
int mistakes=0,mistakes_length,len;
char temp[100];
void lesson1(void);
void lesson2(void);
void result(void);
void main(void)
{
    int choice;
    clrscr();
    printf("Enter a lesson number to practise:1-10 \n");
    scanf("%d",&choice);
    switch(choice)
    {
        case 1:
        lesson1();
        result();
        break;
        case 2:
        lesson2();
        result();
        break;
        default:
        printf("You did not entered a valid choice program quitting..\n");
        exit(0);
    }
    getch();
}
void lesson1(void)
{
    int i;
    char str1[100]="testing the typing tutor if it works";
    mistakes_length=5;
    clrscr();
    gotoxy(25,2);
    puts("Welcome to lesson 1");
    puts(str1);
    len=strlen(str1);
    for(i=0;i<len;i++)
    {
        temp[i]=getche();
        if(strncmpi(&str1[i],&temp[i],1))//does not match
        {
            mistakes++;
            sound(100);
            delay(1000);
            nosound();

        }
    }
    getch();
}
void result(void)
{
    printf("Your statsistics are as under:\nYou performed this lesson with %d mistakes\n",mistakes);
    if(mistakes>=mistakes_length)
        {
                printf("\n Your typing is very bad");//allow anything to be typed with any mistake in lesson 1

        }
        if(mistakes>3&&mistakes<5)
        {
            printf("Bad!,You need to practise this excercise more\n");
        }
        if(mistakes>=1&&mistakes<=3)
        {
            printf("Good!you can still do better\n");
        }
        if(mistakes==0)
        {
            printf("Excellent!You are qualified for the next lesson\n");
            printf("The next lessons password is \n\t\t\t:12345");
        }
}

void lesson2(void)
{
    char password[]="12345",str2[]="My name is khan and i am not a criminal";
    int i;
    mistakes=0,mistakes_length=0,
    printf("Enter password:\n");
    gets(temp);
    if(strcmp(temp,password))
    {
        gotoxy(20,25);
        printf("Wrong Password,Program Quitting.\n");
        getch();
        exit(1);
    }
    gotoxy(25,25);
    printf("Password Accpted!");
    getch();
    clrscr();
    gotoxy(25,2);
    printf("Welcome to lesson 2\n");
    printf("Type the text shown below:\n");
    puts(str2);
    len=strlen(str2);
    for(i=0;i<len;i++)
    {
        temp[i]=getche();
        if(strncmp(&str2[i],&temp[i],1));
        {
            mistakes++;
        }

    }
    getch();
}

I think that it is the scanf and gets together making a problem!

  • 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-16T02:03:41+00:00Added an answer on May 16, 2026 at 2:03 am

    Your problem is that prior to calling gets(), you have called scanf("%d",&choice); (in main()). The problem with this is that console input is line oriented. This means that although you are only waiting for a number to be entered the user has to enter a complete line ending in newline. The %d format specifier only consumes the digit characters leaving the rest of the line in the buffer to be used by the next console input call; which in this case is gets() which sees the newline in the buffer and returns an empty string without waiting for further input.

    A solution:

    scanf("%d",&choice);
    while(getchar() != '\n' ) { /*no nothing*/}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is not working as expected to detect if it is in design
The code below shows a sample that I've used recently to explain the different
The code below works. But if I comment out the line Dim objRequest As
The code below gives an error: Property 'Int32 Key' is not defined for type
Code below takes a directory and creates an array of folder names appearing under
The code below is part of a query. I seem to have the format
Example code below; function a() { var a = 123; //some stuff b(); }
The code below gives me this mysterious error, and i cannot fathom it. I
The code below is the code i am using. It works fine in thunderbird

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.