comparing user input with txt file without using string

I am in trouble to comparing user input with the content in txt file.
let say I have a txt file
line1: username1
line2: pw1
line3: username2
line4: pw2
the user input username1&pw1, how can I compare the user input with the content inside txt file?? As <string> is not allowed to use.

Please help me
First you need to get the user input and store it in variables like:
char username[32], char password[32].
Then to check if you got the input correct just print it on the screen.
This would be the first step.

I hope this gives you enough infos to start coding.
When you have finished the first step post your code and I - or someone else - can help you with the second step.

I wrote this. But it doesn't work....always "false login!"
But I don't know why...

char username[100];
char password[100];
char un[100];
char pw[100];

reg()
{
cout << "select a username: "; cin.getline(un,100);
cout << "select a password: "; cin.getline(pw, 100);
ofstream select("user.txt",ios::app);
select <<un << '\n' << pw<< '\n';
select.close();
}

login()
{
cout << "Enter username: "; cin.getline(username, 100);
cout << "Enter password: "; cin.getline(password, 100);
bool found = false;
ifstream check("user.txt");
while (!check.eof())
{
check.getline(un, 100, '\n');//obtain the username of the text file
check.getline(pw, 100, '\n');//obtain the password of the text file
if (un == username && pw == password)
{
cout << "successfully logged in!" << endl;
found = true;
break;
}
}
if (found == false)
{
cout << "false login!" << endl;
}
check.close();
break;
}
if (un == username && pw == password)

You have to use the function strcmp to compare these char arrays.
http://www.cplusplus.com/reference/cstring/strcmp/

== works with std::strings
Topic archived. No new replies allowed.