473,378 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Problem using bsearch

Hi,

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
0 1487

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

Similar topics

1
by: Ramprasad A Padmanabhan | last post by:
I have written a simple script to search a word in an array But bsearch does not seem to work here. I know I am missing out something very simple , But I am not able to find out what Thanks...
4
by: Angus Comber | last post by:
Hello I have received a lot of help on my little project here. Many thanks. I have a struct with a string and a long member. I have worked out how to qsort the struct on both members. I can...
6
by: Michiel Rapati-Kekkonen | last post by:
bsearch finds me only the first occurrence of something I'm looking for, but I would like to know the place in the list where it is found. The index of it's place in the array. So that I can check...
13
by: val | last post by:
Hi, I found that Windows CE doesn't include bsearch function. Can somebody point me into right direction in order to solve that issue Thanks, val
3
by: c_programmer | last post by:
I have a problem. There is a effective dated list FAMILY_ACCOUNTS stored in the memory. How to achieve the equivalent of the following SQL statement: select * from FAMILY_ACCOUNTS FA where...
4
by: Davy | last post by:
For example, I have a vector: double vector={1.11,2.38,4,53,17.14...,89.12,91.34} And if the Key I want is 5.2, the nearest item will be 4,53. I found that if the STEP of the vector is constant,...
2
by: Bit Byter | last post by:
I am hacking some legacy code and have put together a simple test to test some hashing funcs I've written. I now want to do a simplistic timing between the various structs. Here's a snippet: ...
4
by: Steph | last post by:
Hello, I have filled a dynamic array of strings (realloc() + malloc()) char **sMyArray; At the end, I get correctly sMyArray = "STRING_0", sMyArray = "STRING_1", etc... But I'm unable to...
4
by: Amandil | last post by:
Hi, all. I'd like to check whether a certain string (one that I got from a user, or read from a file) is contained in a table of strings. The format of the table is char *table = { "string1",...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.