I have a function which checks for username and password. I have two text files, one for a single line username and the other for a single line password. I then read this data from txtfile and store them as 2 strings. Then I compare these with the username and password input by the user using the function which returns 1 for success. But my code gives the wrong output.
int compare(char C[], char E[])
{
    ifstream fil1;
    ifstream fil2;
    fil1.open("user.txt", ios::in);
    fil2.open("pass.txt", ios::in);
    char ch1, ch2;
    char B[50], F[50];
    int i1 = 0, i2 = 0;
    while (!fil1.eof())
    {
        fil1.get(ch1);
        F[i1] = ch1;
        i1++;
    }
    F[i1] = '\0';
    fil1.close();
    while (!fil2.eof())
    {
        fil2.get(ch2);
        B[i2] = ch2;
        i2++;
    }
    B[i2] = '\0';
    fil2.close();
    int flag;
    int X = strlen(E);
    int Y = strlen(B);
    if (X == Y)
    {
        if ((strcmp(C, F) == 0) && (strcmp(E, B) == 0))
            flag = 1;
        else
            flag = 0;
    }
    else
        flag = 0;
    return flag;
}
It gives the wrong output even when username and password are right. Where is the error??
 
     
     
    