Thread: What did i do wrong? Code inside

  1. #1
    Registered User
    Join Date
    May 2002

    Arrow What did i do wrong? Code inside

    Kay, Rookie here, trying some kind of lowlvl password check, it prolly contains alot of errors, but i cant see what exactly is wrong i think the check on if( passwordentered[i] == 1234 ) is wrong and you??

    #include <stdio.h>

    void main() {

    char passwordentered[8];
    char passlist[4];
    bool enter = false;
    int i;

    passlist[1] = 1234;
    passlist[2] = 1111;
    passlist[3] = 5644;

    printf("enter your password: \n");
    scanf("%s", &passwordentered);

    if( passwordentered[i] == 1234 )
    enter = true;
    printf("Password is correct\n");
    enter = false;
    printf("Password is incorrect\n");


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > i think the check on if( passwordentered[i] == 1234 ) is wrong and you??
    Yes, I think it's wrong as well

    > void main() {
    So is this

    > bool enter = false;
    This is C++ only, yet this is the C board

    > passlist[1] = 1234;
    What are you doing here
    Trying to set up one password or three?

    > scanf("%s", &passwordentered);
    Mmm - should be
    scanf("%s", passwordentered );
    Since passordentered is already an array

    > for(i=0;i<10;i++)
    10 what exactly?
    I see 4's and 8's, but no 10's

    > if( passwordentered[i] == 1234 )
    You probably want something like
    if( strcmp(passwordentered[i],"1234") == 0 )

  3. #3
    Registered User
    Join Date
    Aug 2001
    First off, it's int main, which will return 0.

    Next, bool is not a type that C understands, so instead, you'll have to do something like:
    int enter = -1; //Set enter to false

    Later on you can set enter to true by giving it a value greater than -1. On that subject, I can't tell what enter is doing there anyway, unless this is part of a larger program and for some reason you want the value.

    Secondly, change passwordentered[] and passlist[] to int types. Since you're only dealing with numbers, you won't need to worry about chars.

    That'll make it compile, I'll leave the rest to you or someone else to solve.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's wrong with this code?
    By Luciferek in forum C++ Programming
    Replies: 4
    Last Post: 06-21-2008, 12:02 PM
  2. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  3. loop and compiling inside a code
    By MtJ in forum C Programming
    Replies: 3
    Last Post: 03-05-2006, 12:50 PM
  4. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM