reading a string from file and comparing it with another file

suppose a file is containing 10 lines of some names, passwords and permissions
initialy it should search the name in the file given from outside the file and if found it should return o, if not found increment the count to 1
soujanya i will give you the algorithm and let the code for you ^-^

open file
cheak if the file is not empty "use built in function"
read the first line from the file
open the other file
cheak if it is not empty
read the first line of that file

use while(while not end of file) loop to cheak if for ex:id1==id2;
if yes the return
else
increment the variabel

this is the basic ida it realy depend on your knoledge
if you now how to use functions it will be more easier.
sir actually

basic idea is this

my process is that if user should not enter the username wrong more than 3 times iin the user interface .in case he enters that particular user is locked in similar way if more than 10 user names he enters wrong then the system is locked

for this reason i will take two int variables=0 which count my system and user

now coming to my file

for example my file consists of these lines
janaki pijanaki 1
shailaji suresh 2
jeans jai 3



i mean to say my first word will be user name, second will be password and third will be permission which is 1 for read and 2 for write and so on

now in my code i have open a file and am able to read a line using getline() function
.through some class object am getting the username member variable

now i have to check whether this username member variable is there in my file i,e it should check in each line of the file till the end of the file if yes
then it should simple return 0 if no then it should increment my user count

can u please suggest me and if possible cn u give me the code.

since am the learner in c++. it is my request.
sir i wanted to give the code what i have done please suggest me how to get the searched string in a file to variable so that i can compare that string with the string i have read from my user interface if it is equal then hash code should be generated else it should increment the user count to 0 and system count to 0 these values should be updated in my file to the end of that particular usernames .
here is the code

#include<iostream.h>
#include<fstream>



using namespace std;

int usercount=0, syscount=0;



int Form1::access()
{ifstream Myfile("cityFile.txt");
if(Myfile.is_open())
{
while(!Myfile.eof())
{
string line;
string name=filename->text();
string password=pwd->text();


int offset;
getline(Myfile,line);
cout<<line<<endl;

if ((( line.find(name, 0)) &&(( line.find(password,0))) != string::npos) )


cout<<"'"<<name<<"'"<<endl;
cout<<"'"<<password<<"'"<<endl;


}

Myfile.close();

}

else
cout<<"unable to open the file";
return 0;


}


for example my text file is containing the following data
radha kradha 1 0 3
malli kmakki 0 1 3


first is user name, second column is password and third column is permission
sir i wanted to give the code what i have done please suggest me how to get the searched string in a file to variable so that i can compare that string with the string i have read from my user interface if it is equal then hash code should be generated else it should set the user count to 0 else increment the usercount to 1(should not be more than 3, otherwise user is locked) and system count(it should be<=10, if it exceeds then system is locked) to 0 these values should be updated in my file to the end of that particular usernames .
here is the code

#include<iostream.h>
#include<fstream>



using namespace std;

int usercount=0, syscount=0;



int Form1::access()
{ifstream Myfile("cityFile.txt");
if(Myfile.is_open())
{
while(!Myfile.eof())
{
string line;
string name=filename->text();
string password=pwd->text();


int offset;
getline(Myfile,line);
cout<<line<<endl;

if ((( line.find(name, 0)) &&(( line.find(password,0))) != string::npos) )


cout<<"'"<<name<<"'"<<endl;
cout<<"'"<<password<<"'"<<endl;


}

Myfile.close();

}

else
cout<<"unable to open the file";
return 0;


}


for example my text file is containing the following data
radha kradha 1 0 3 1
malli kmakki 0 1 3 2


first is user name, second column is password and third column is permission fourth is my user count and fifth is system count
sir i could found the solution and am able to find the valid username and valid password from the file. now my question actually i was given 4 conditions for username and password on which the user count and system count depends

1. when username is right and password is wrong then my systemcount and user count shud be increased to 1
2.when username is wrong and password is right then my usercount is incremented

3.when username and password is wrong then my system count shud be incremented
4. when both are right then user count shud b incremented .

how do i do this.

please suggest me with my given code here.

r may i request u to give me the proper code. as am a beginner.
i request u to reply as early as possible. thank u for the hint u have given earlier.




#include<iostream.h>
#include<fstream>
#include<string>

using namespace std;

enum{FIRST,SECOND};

void split_string(string userData, string &s1, string &s2)
{
string::iterator i;
int state= FIRST;
for(i=userData.begin(); i!=userData.end(); i++)
{
if(*i =='&')
{
state=SECOND;
}
else if(state==FIRST)
{
s1.push_back(*i);
}
else if(state==SECOND)
{
s2.push_back(*i);
}
}
}

void split_string(string s,string &s1 , string &s2);

int Form1::access()
{
string line;
ifstream Myfile("cityFile.txt");

string name=filename->text();
string password=pwd->text();
string n=name.append("&");
string userData=n.append(password);
string fname,fpassword;

if(Myfile.is_open())
{
int foundName =0;
int found = 0;
int foundPass = 0;
while (!Myfile.eof())
{
int offset;
getline(Myfile,line);


if ( !foundName && (line.find(userData,0) ) !=string::npos )
{


fname="",fpassword="";
cout<<userData<<endl;
split_string(userData,fname,fpassword);

foundName = 1;
}

if( foundName )
{
found = 1;
break;

}


}
if( (found==0) || (fname=="") || (fpassword=="" ) )
{
cout<<"not found"<<endl;
}
else {
cout<<"found"<<endl;
}

Myfile.close();
}

}



eagerly waiting for ur reply
are you asking how to do string compare?
yes,
but i have done string comparisons. if it is true(when username and password is found in the file)
then my usercount is set to 0 for that particular username

my question is if wanted to append new value to a line then do i required to remove that line and add new line with modified values. if so

how do i delete the line in a file depending upon the username found.

please give the reply.its very urgent.
please suggest me with the reply as early as possible.
Topic archived. No new replies allowed.