Hello I'm working on this final project. I need to create an ATM program with a unique pin code. However every time I run the p I have done 3 hours of researching and I've decided to just ask. What am I doing wrong that it's just running the do while 3 times whenever I enter a 4 digit pin?

void Pin()
        printf("\n\t Please enter your 4 digit PIN \n ");
        scanf_s("%[^\n]\n", &pin);
        *Count = *Count + 1;
        if (*Count >= 3)
            printf("Sorry you can't continue, contact your bank for assistance!\n");
    }while(strlen(pin) != 4 && *Count < 3);
2 Years
Discussion Span
Last Post by Ancient Dragon

How is pin declared? Assuming it's char pin[5]; line 6 should be
scanf_s("%s", pin); Note you don't need the & address symbol because the compiler will always pass the address of arrays.


I suspect the real problem is an old issue which comes up from time to time in C: the fact that the standard C I/O functions are all buffered, stream oriented functions, and that there is no standard way of getting unbuffered ('raw') console input. What this means is that you can't read from the keyboard character by character as it is typed in - you have to wait for the user to hit enter, and get the whole line of input at once (though you can read the buffer character by character once it is entered).

Since you are already using a Windows specific function (namely, scanf_s()), it is safe to say you are free to use the Windows console functions, correct? They are a lot more work, but they will do what you want.

Edited by Schol-R-LEA


When I did

        scanf_s("%s", pin);

It locked up the program and reffered me to a program called mlock.c


how is pin declared? You never posted it, so no one here really knows. In order for that to work pin must be a character array. If pin is an int then you need to use "%d" instead of "%s"

Edited by Ancient Dragon

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.