By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

Problem using bsearch

P: 1

I am facing a problem using bsearch . Even though the data Im searching for is present in the array, the function returns a NULL object.

The array is a structure with the following definition

struct ppcData
char MSISDN[13];
char StatusInFile[15];
double Value; /* Card Balance */
char ExpDate[20]; /* Expiry Date */
char State; /* State - Active or Grace */
char Status;

The search statement is as follows -

ppcptrObj=bsearch ( &pCurPPCFilteredData[i], pPrevPPCFilteredData, PrevPPCRecordCount, sizeof(struct ppcD
ata), cmpPPCData );

The comparison function is as under -

int cmpPPCData(const void *pv1, const void *pv2)

struct ppcData *v1 = (struct ppcData *) pv1;
struct ppcData *v2 = (struct ppcData *) pv2;

if( strlen(v1->MSISDN) != strlen(v2->MSISDN) )
return strlen(v1->MSISDN) - strlen(v2->MSISDN);

return strcmp(v1->MSISDN, v2->MSISDN);

Pls. help as the data Im searching for is present in the array, but if the number of elements is increased by 1 (PrevPPCRecordCount + 1) ,then the data is found.

Currently, The array has 3 records.

Request you to please help
Mar 30 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.