plz help me anybody regarding this program

This is a discussion on plz help me anybody regarding this program within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream.h> #include<conio.h> #include<string.h> void main() { clrscr(); char a[]="soft",b[4]; int i,n; for(i=0;a[i]!=NULL;i++) { b[i]=getch(); cout<<"*"; } n=strcmp(b,a); if (n==0) ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    1

    Unhappy plz help me anybody regarding this program

    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    void main()
    {
    clrscr();
    char a[]="soft",b[4];
    int i,n;
    for(i=0;a[i]!=NULL;i++)
    {
    b[i]=getch();
    cout<<"*";
    }
    n=strcmp(b,a);
    if (n==0)
    cout<<"Welcome";
    else
    cout<<"Invalid Password";
    getch();
    }
    when i m running this program i always get invalid password...........
    Last edited by Salem; 04-30-2010 at 09:54 AM. Reason: Added [code][/code] tags - learn to use them yourself (as well as how to indent code)

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,261
    First, please use [code][/code] tags

    You cannot compare characters arrays that are not null-terminated using strcmp. 'b' needs to be long enough to hold 5 characters to include the null character. You should ideally use '\0' for the nul-terminator as well, rather than NULL, for clarity.
    Also, main must return int, never void.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  3. plz help me with simple string comparison.
    By MegaManZZ in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2008, 12:11 PM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21