worries with the main logic of endswith !

reference : http://satisheerpini.blogspot.com/2008/04/endswith-function-in-c.html
i have been having enough problems getting the main logic of the endswith function right, .... the code for the main loop in the program which does the string matching is as follows :
____________________________________________________________________________________
for(i=0;i dir_recd_len;i++){
if(i<(dir_recd_len-comp_str_len))
continue ;
else{
/*
* the first error lay here , i forgot to give the
* brackets at (85,19) and (85,45), that gave negative values
* during iterations , which was disastrous
*/
if(argv[2][i-(dir_recd_len-comp_str_len)]==dir_recd->d_name[i]){
flag=1;
}
else{
flag=0;
/*
* could not use exit(0) or break here
* because , exit would take it completely
* out of the loops ,and i was not sure
* of using break , has to be changed soon
*/
goto out;
}
}
}
out:
/*
* final check if the file name in the directory had
* the given ending
*/
if(flag==1 ){
printf("%s\n",dir_recd->d_name);
no_of_matches++;
}

____________________________________________________________________________________
while the problem is that, the program works very well when the string pattern to be matched is a part of the existing file name , but when the string pattern is a super-set of the existing file names , it also displays the file names which are a subset of the given string pattern .The first time i discovered this problem was when i ran the following command , where i had the files mplayer and gmplayer in my root directory :
endswith /root gmplayer
OUTPUT :
gmplayer
mplayer
it gives both mplayer and gmplayer as the output , where as only gmplayer should be displayed .Have not been quite successful in figuring out the error !

Comments

Popular posts from this blog

Was history ! :)

beginning again

installing RadRails on Eclipse ...........