Results 1 to 1 of 1

Thread: Debug error: Invalid parameter passed to C runtime function.

  1. #1
    Join Date
    Mar 2010
    Posts
    56
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Debug error: Invalid parameter passed to C runtime function.

    I want use binaysearch but it give an error when bsearch try to call comparator. The debug error is: "Invalid parameter passed to C runtime function"; I can't figure it out :S

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QtCore>
    3. #include <QtGui>
    4.  
    5. #include <fcntl.h>
    6. #include <stdio.h>
    7. #include <stdlib.h>
    8. #include <sys/stat.h>
    9.  
    10. #define RECORD_SIZE (6+10+1)
    11.  
    12. int comparator(const void *a, const void *b);
    13.  
    14. MainWindow::MainWindow(QWidget *parent)
    15. : QMainWindow(parent)
    16. {
    17. //QString *ssid = new QString("60EFF9");
    18. QString dir = QFileDialog::getOpenFileName(this, tr("Select Text File"),"",tr("Text (*.txt)"));
    19. QFile f(dir);
    20. qint64 fileSize = f.size();
    21.  
    22. uchar* ptr = f.map(0,fileSize,QFile::NoOptions);
    23.  
    24. char *ssid="60EFF9";
    25.  
    26. char *res =(char*) bsearch(ssid, ptr, fileSize / RECORD_SIZE, RECORD_SIZE, (int(*)(const void*, const void*))comparator);
    27.  
    28. if (NULL == res) {
    29. qDebug()<<("No match!!");
    30. } else {
    31. qDebug("Match found: %.10s\n", res+6);
    32. }
    33.  
    34. }
    35.  
    36. MainWindow::~MainWindow()
    37. {
    38.  
    39. }
    40.  
    41. int comparator(const void *a, const void *b)
    42. {
    43. qDebug()<<"IN";
    44.  
    45. const char *aa = (const char *)a, *bb = (const char *)b;
    46.  
    47. for (int i = 0; i < 6; ++i) {
    48. if (aa[i] != bb[i]) {
    49. return aa[i] - bb[i];
    50. }
    51. }
    52. return 0;
    53. }
    To copy to clipboard, switch view to plain text mode 


    Added after 55 minutes:


    SOLVED: i call f.map(...) before open the file
    Last edited by metRo_; 24th October 2010 at 19:09.

Similar Threads

  1. Replies: 1
    Last Post: 25th September 2010, 08:20
  2. Replies: 4
    Last Post: 2nd April 2010, 10:04
  3. Replies: 3
    Last Post: 17th July 2008, 07:43
  4. skip function parameter
    By mattia in forum General Programming
    Replies: 4
    Last Post: 22nd November 2007, 15:55
  5. const function parameter problems
    By stevey in forum General Programming
    Replies: 3
    Last Post: 18th December 2006, 22:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.