Cześć,
Napisałem program, który maskuje hasło w jezyku C, ale mam mały problem - otóż wyskakuje komunikat segmentation fault.
Czy mógłby ktoś wyjaśnić co robię źle?
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#define TIME 10
#define PASSWORD "pass123"
void sigalrm_handler() {
printf("\nERR: Czas uplynal...\n");
exit(1);
}
int main(int argc, char * argv[]) {
char password[9];
printf("Wpisz haslo, masz na to %d sekund: ", TIME);
signal(SIGALRM, sigalrm_handler);
alarm(TIME);
fflush(stdout);
for(int i=0; i<9; i++)
{
password[i] = getch();
printf('*');
}
if (strcmp(password, PASSWORD) == 0) {
printf("Haslo poprawne!\n");
exit(0);
} else {
printf("ERR: Haslo niepoprawne\n");
exit(2);
}
pause();
return 0;
}