This is diary writing program that gives me problem with login function.
void MainMeni();
void PisanjeDnevnika();
void LogIN(){
char username[50];
char password[500];
FILE * fpointeru = fopen("C:\\Users\\marmun\\Desktop\\dnevnik\\login.txt", "r");
FILE * fpointerp = fopen("C:\\Users\\marmub\\Desktop\\dnevnik\\login.txt", "r");
fgets(username, 50, fpointeru);
fgets(password, 50, fpointerp);
fgets(password, 50, fpointerp);
fclose(fpointeru);
fclose(fpointerp);
char Username[50];
char Password[500];
int i;
int o;
do{
printf("Input user\n");
scanf("%s", Username);
So if username input is eqqual to username stored in registration before it should login otherwise loop until user matches it. But after user puts the first letter matching the first letter of stored username program breaks and lets user in. Also strcmp only returns 1 and -1.
i = strcmp(username, Username);
printf("%d", i);
if(i == 0){
printf("Login succes!");
}
else if(i != 0){
printf("Login unssuceful\n!");
LogIN();
printf("%s", Username);
}
system("cls");
}while(i != 1);
do{
printf("Input password\n");
scanf("%s", Password);
o = strcmp(password, Password);
printf("%d\n", o);
if(o == 1){
printf("Password correct!\n");
}
else if(o != 1){
printf("Password inncorect!");
}
}while(o != 1);
char Izbor;
printf("\Login succesuful!");
printf("\n\tChoose 1 out of 3 options!");
printf("\t1.Meni\n\t2.Writing diary.\n\t3.Exit");
scanf("%c", Izbor);
do
{
switch(Izbor){
case '1':
MainMeni();
case '2':
PisanjeDnevnika();
case '3':
break;
}
while(Izbor != '1' || Izbor != '2' || Izbor != '3');
system("cls");
}