#include "mainwindow.h"
#include <QtCore>
#include <QtGui>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#define RECORD_SIZE (6+10+1)
int comparator(const void *a, const void *b);
MainWindow
::MainWindow(QWidget *parent
){
//QString *ssid = new QString("60EFF9");
QString dir
= QFileDialog::getOpenFileName(this, tr
("Select Text File"),
"",tr
("Text (*.txt)"));
qint64 fileSize = f.size();
uchar
* ptr
= f.
map(0,fileSize,
QFile::NoOptions);
char *ssid="60EFF9";
char *res =(char*) bsearch(ssid, ptr, fileSize / RECORD_SIZE, RECORD_SIZE, (int(*)(const void*, const void*))comparator);
if (NULL == res) {
qDebug()<<("No match!!");
} else {
qDebug("Match found: %.10s\n", res+6);
}
}
MainWindow::~MainWindow()
{
}
int comparator(const void *a, const void *b)
{
qDebug()<<"IN";
const char *aa = (const char *)a, *bb = (const char *)b;
for (int i = 0; i < 6; ++i) {
if (aa[i] != bb[i]) {
return aa[i] - bb[i];
}
}
return 0;
}
#include "mainwindow.h"
#include <QtCore>
#include <QtGui>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#define RECORD_SIZE (6+10+1)
int comparator(const void *a, const void *b);
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
//QString *ssid = new QString("60EFF9");
QString dir = QFileDialog::getOpenFileName(this, tr("Select Text File"),"",tr("Text (*.txt)"));
QFile f(dir);
qint64 fileSize = f.size();
uchar* ptr = f.map(0,fileSize,QFile::NoOptions);
char *ssid="60EFF9";
char *res =(char*) bsearch(ssid, ptr, fileSize / RECORD_SIZE, RECORD_SIZE, (int(*)(const void*, const void*))comparator);
if (NULL == res) {
qDebug()<<("No match!!");
} else {
qDebug("Match found: %.10s\n", res+6);
}
}
MainWindow::~MainWindow()
{
}
int comparator(const void *a, const void *b)
{
qDebug()<<"IN";
const char *aa = (const char *)a, *bb = (const char *)b;
for (int i = 0; i < 6; ++i) {
if (aa[i] != bb[i]) {
return aa[i] - bb[i];
}
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks