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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:00:10+00:00 2026-06-08T01:00:10+00:00

Why does it always show Invalid Password ? It works in my other program

  • 0

Why does it always show Invalid Password? It works in my other program but in this one it doesn’t! I literally cant figure out why.

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#define MAXLTR 15
int login(void);
void welcome(void);
void gotoxy(int x,int y);

int main(void)
{   
    char password[MAXLTR];
    printf("\nEnter password: ");
    //scanf("\n%s",&password);
    ltrcntr = 0;
    while(buffer != 13)
    {
        buffer = getch();
        if(buffer == 13)
                  break;
        printf("\b**");
        password[ltrcntr] = buffer;
        ltrcntr++;
    }
    if(strcmp(password,"dlsu") == 0)
    {
        system("cls");
        welcome();
    }
    else
        printf("\nInvalid Password, please rerun the program.\n");


}
void gotoxy(int x, int y)
{
     HANDLE eric;
     COORD pogi;
     pogi.X = x;
     pogi.Y =y;
     eric = GetStdHandle
     (STD_OUTPUT_HANDLE);
     SetConsoleCursorPosition
     (eric, pogi);
}
int login(void)
{
    char password[MAXLTR],buffer;
    int ltrcntr = 0;
    printf("Enter password: ");
    while(buffer != 13)
    {
        buffer = getch();
        if(buffer == 13)
                  break;
        printf("\b**");
        password[ltrcntr] = buffer;
        ltrcntr++;
    }
    if(strcmp(password,"dlsu")==0)
        return 1;

}

void welcome(void)
{
    system("Color 4F");
    gotoxy(35,56);
    printf("\nWelcome to SPACE INVADERS!");
}
  • 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-08T01:00:13+00:00Added an answer on June 8, 2026 at 1:00 am

    C strings are NULL terminated (i.e., the last character is \0). All C functions which operate on strings expect this because it is the only way to know where the string ends. You array could be filled with anything as it is uninitialized. Try this:

    char password[MAXLTR] = {0};
    

    strcmp expects a NULL terminated string. Also, if a carriage return is never entered (and I don’t even see where buffer is declared…) you will overrun your password buffer.

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

Sidebar

Related Questions

I wonder, using Eclipse's PyDev plugin , how come documentation does not always show
Why does Thunderbird always return immediately after sending mail through MAPI? Other clients, like
Does this code always evaluate to false? Both variables are two's complement signed ints.
Why does this code always return 0? var possibleMatches = new Array(); $.getJSON('getInformation.php', function(data)
I am adding MediaController to a VideoView, but it does not show up unless
My application does not break during Runtime. However, the following error messages always show
This may be something I just have to live with, but does the blockUI
Does anyone know how to show a asp:TreeView always expanded to the leaves? So
Why does the below alert always show me null? <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs
I want an animated picture. But I need a refresh-function because plt.show() always opens

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.