Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

c - my if and while structure isnt working properly

Guys ?m tring to do wrong username and password part for my login program but if the user gets one of them wrong program sends user to login but did not stop there.what is my problem here? ? think problem is the not registered part but ? cannot find a way to bypass it.and ? need to add we cannot use goto for it

void login()
{
    FILE* fp;
    char c, nama[30], pass[30]; int z = 0; 
    int cekun, cekpw;
    fp = fopen("file.txt", "r");
    for (i = 0; i <= 10; i++)
    {
        printf("

  username: ");
        scanf("%9s", nama);

        system("cls");
        printf("

 password: ");
        while ((c = _getch()) != 13)
        {
            pass[z++] = c;
            printf("%c", '*');
        }
        pass[z] = '';
        while (!feof(fp)) 
        {
            fscanf(fp, "%30s %30s", w[i].nama, w[i].pass); 
            cekun = strcmp(nama, w[i].nama);
            cekpw = strcmp(pass, w[i].pass);
            if (cekun == 0 && cekpw == 0)
            {
                system("cls");
                printf("


 succesfully entered!");
                break;
            }
            else if (cekun == 0)
            {
                printf("


 wrong password !");
                printf("

  (press [Y] for reregistiration )");
                if (_getch() == 'y' || _getch() == 'Y')
                    system("cls"); login();
            }
            else if (cekpw == 0)
            {
                printf("


YANLI? KULLANICI ADI!");
                printf("

  (press [Y] reregistiration )");
                if (_getch() == 'y' || _getch() == 'Y')
                    system("cls"); login();
            }
        }
        if (cekun != 0 && cekpw != 0) 
        {
            printf("


not registered
  press [ENTER] for registiration ");
            if (_getch() == 13)
                system("cls");
            reg();
        }
        break;
    }
    _getch();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...