Re: Binary Search - Error
Are your entries null-terminated? If yes, why don't you use strcmp as comparator, if not qDebug will crash.
Re: Binary Search - Error
I use the compartor because i need to compare the first 6 bytes of a total of 17 bytes. I tried to compile to desktop and it's works perfectly. The aplication in the mobile doesn't start so i can't even choose the file.
Re: Binary Search - Error
Try this sample console application
[CODE]
#include <QtCore>
int main(int argc, char **argv)
{
QFile file("myfile.txt");
if(file.open(QIODevice::ReadOnly)) {
int fileSize = file.size();
int recordSize = 17;
char ssid[] = "60EFF9";
uchar* ptr = file.map(0, fileSize);
char *res = (char*)bsearch(ssid, ptr, (fileSize / recordSize), recordSize,
(int(*)(const void*, const void*))strcmp);
if (res)
qDebug("Match found: %.10s\n", res+6);
else
qDebug() << "No match!!";
} else {
qDebug() << file.errorString();
}
}
[/CODE]
Re: Binary Search - Error
It run but the console close before i can read what it says.
Re: Binary Search - Error
You should see at least "No such file or directory" debug message.
Re: Binary Search - Error
[QUOTE=divanov;787966]You should see at least "No such file or directory" debug message.[/QUOTE]
i change "myfile.txt" to my file.
Re: Binary Search - Error
If i compile it to mobile it give the same error as my aplication!
Re: Binary Search - Error
Do you have ReadUserData capability?
Re: Binary Search - Error
[QUOTE=divanov;787975]Do you have ReadUserData capability?[/QUOTE]
No, but my problem was that Symbian doesn't like:
int a;
int b;
int c=(a/b); ---> It make my aplication didn't start up! Error:"Not Supported function";
Char - A data abort exception has occurred.
Hi, when i call this funcion: char *res =(char*) bsearch(ssid, ptr, 9704447, 17, comparator); i use a comparator function and my aplication crash!
comparator():
[CODE]int comparator(const void *a, const void *b)
{
qDebug()<<"comparator()";
const char *aa = (const char *)a, *bb = (const char *)b;
qDebug()<<"1";
for (int i = 0; i < 6; ++i) {
qDebug()<<"2";
qDebug()<<"i:"<<i;
qDebug()<<"i:"<<i<<" aa:"<<aa[i]<<" bb:"<<bb[i];
qDebug()<<"3";
if (aa[i] != bb[i]) {
return aa[i] - bb[i];
}
}
return 0;
}[/CODE]
the debug:
[COLOR="blue"]Executable file: 9058 2010-10-25T01:46:47 C:\NokiaQtSDK\Symbian\SDK\epoc32\release\gcce\udeb\meoKeyMap.exe
Package: 9380 2010-10-25T01:46:50 C:\Users\Ze\Documents\Qt\meoKeyMap\meoKeyMap.sis
Deploying application to 'Nokia E51 USB (COM4)'...
Copying installation file...
Installing application...
Starting application...
Application running with pid 875.[/COLOR]
[Qt Message] comparator()
Process 875, thread 876 stopped at 0x7b95028c: A data abort exception has occurred.
[Qt Message] 1
[Qt Message] 2
[Qt Message] i: 0
[COLOR="blue"]Finished.[/COLOR]
Re: Binary Search - Error
[QUOTE=metRo_;787984]No, but my problem was that Symbian doesn't like:
int a;
int b;
int c=(a/b); ---> It make my aplication didn't start up! Error:"Not Supported function";[/QUOTE]
The only problem here is that a and b are not initialized and b could possible be zero.
If you change it to something like this, then no problem
[CODE]
int a = 10;
int b = 20;
int c = (a / b);
[/CODE]
GUI sample application
[CODE]
#include <QtGui>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QLabel label;
QFile file("myfile.txt");
if(file.open(QIODevice::ReadOnly)) {
int fileSize = file.size();
int recordSize = 17;
char ssid[] = "60EFF9";
uchar* ptr = file.map(0, fileSize);
char *res = (char*)bsearch(ssid, ptr, (fileSize / recordSize), recordSize,
(int(*)(const void*, const void*))strcmp);
if (res)
label.setText(QString("Match found: %1").arg(res+6));
else
label.setText("No match!!");
} else {
label.setText(file.errorString());
}
label.show();
return app.exec();
}
[/CODE]