Skip to content

Instantly share code, notes, and snippets.

@antonva
Created October 19, 2015 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonva/fdfbc9e97cce8bb7304b to your computer and use it in GitHub Desktop.
Save antonva/fdfbc9e97cce8bb7304b to your computer and use it in GitHub Desktop.
#include <stdio.h>
void init_input(int input[], size_t psize) {
for (size_t i = 0; i < psize; i++) {
input[i] = 99;
}
}
int check_password(int *password, size_t psize, int *input) {
for (size_t i = 0; i < psize; i++) {
printf("%i | ", i);
printf("%i, %i\n", password[i], input[i]);
if (input[i] > 9) { return -2; } //Means that the input isn't long enough.
if (password[i] != input[i]) { return -1; } // No need to check more digits.
}
return 1;
}
int main() {
size_t psize = 4;
int password[] = {1,3,3,7};
int input[4];
init_input(input, psize);
input[0] = 1;
input[1] = 3;
input[2] = 3;
input[3] = 7; // This would be your keypad input. Try fucking around with it.
int val = check_password(&password, psize, &input);
printf("%i\n", val);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment