hi all..
I dont know how to search for a string in a file.. I have tried doing.. I did google but didnt get effective answers..my code is as follows:
int search(char* filename,const char*
username,const char* passwd)
{
int flag=0;
unsigned long fsize=0;
unsigned long current=0;
int fdsearch=-1;
int cun,cpw;
char *user,*pass;
int un,pw;
pw=strlen(passwd);
un=strlen(username);
fdsearch=open(filename,O_RDONLY);
fsize = lseek(fdsearch, 0L, 2);
user=(char*)malloc(un);
pass=(char*)malloc(pw);
while (current<fsize)
{
lseek(fdsearch,current,SEEK_SET);
cun=read(fdsearch,user,un);
cpw=read(fdsearch,pass,pw);
if(!memcmp(username,user,un))
{
if(!memcmp(passwd,pass,pw))
{
flag=1;//found
close(fdsearch);
return(flag);
}
printf("incorrect password");
close(fdsearch);
return(flag);
}
//increment current position by 1
current++;
}//while
return flag;
}
I dont know how to read end of string(space will be the delimiter in the file),then end of line.
i guess the bolded areas are where I am doing mistakes..
kindly help me...
thanks in advance