bsearch

    14熱度

    2回答

    我注意到,從Ruby 2.0.0開始,數組類有一個bsearch方法,我正在測試並且沒有得到我期望的行爲。爲什麼它爲2和5返回一個值,但是爲-1,1和4返回nil? arr_in = [-1, 1, 2, 4, 5] arr_in.bsearch { |x| x == 3 } #=> nil arr_in.bsearch { |x| x == -1 } #=> nil arr_in.bse

    1熱度

    1回答

    在C中使用bsearch未能在結構數組中找到字符串'Eva Lam'。該數組按字符串成員的降序排序。我檢查了很多次,仍然不知道錯誤在哪裏?順便說一句,我正在使用DEV C++ 5.9.4。請幫助,非常感謝。 #include <stdio.h> #include <stdlib.h> // for bsearch #include <string.h> #define SIZE 4 #d

    0熱度

    1回答

    我有一個結構: typedef struct entry_t { char * name; int lines [MAX]; int n;/*n lines*/ } entry_t; 和結構entry_t * list[MAX]; 我嘗試使用bsearch如果一個人在我下面的函數的存在是爲了得到一個條目的數組: int addToList(entry_t * l

    2熱度

    1回答

    我正在使用調用標準函數bsearch()的正則表達式庫。當使用VS2008時,我必須包含一個用於聲明此函數的額外頭文件(<search.h>)。 但是當我連接時,它說bsearch無法解析。 MSDN頁面(https://msdn.microsoft.com/en-us/library/w0k41tbs%28v=vs.90%29.aspx)沒有指出任何要添加鏈接的.lib,所以我不知道該怎麼做!

    1熱度

    1回答

    有人能告訴我爲什麼在這個程序中bsearch函數總是返回指針= NULL? #include <stdio.h> #include <stdlib.h> #include <string.h> struct data { char name[10]; int age; char eye[15]; }; int komparator (const v

    3熱度

    2回答

    我有一個C++類,但我也使用一些低級別的C,並需要使用bsearch函數。 bsearch的最後一個參數是一個比較函數,我想以一種允許它訪問類的常量私有變量的方式實現所述函數。 問題是,如果我使比較函數成員函數它將無法正常工作,因爲它不會轉換爲常規函數指針。如果我創建一個非成員函數,我可以將它傳遞給bsearch,但不能訪問該類的私有變量。 怎麼辦? 例如: 3意味着有3 elements.16,

    0熱度

    1回答

    我使用bsearch用鑰匙值相當於這就是值的陣列元素的指針,一個char是一個指針。關鍵是數組的元素是一個字符指針數組。我不認爲你可以通過索引取消引用數組元素的值,並將值用作指向char字符串的指針。我試着將元素值轉換爲(char *),但沒有奏效。我得到垃圾回報bsearch的價值。 #include <stdio.h> #include <string.h> #include <stdli

    -1熱度

    1回答

    我有以下程序: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <errno.h> #define DICT_BUFSIZE 64 int compar(const void * a, const void * b) { const char*

    0熱度

    2回答

    我試圖將目錄中的文件與其他目錄中的其他文件及其子目錄中的文件匹配使用ruby。 我嘗試使用這個文件的架構做一個小試驗: tree . . ├── src │   ├── lol │   │   └── toto │   └── lolilolpouet │   └── tutu │   └── tata ├── test │   ├── tata │   └── toto

    0熱度

    2回答

    我正在做一個使用C語言的代碼練習。 如下代碼, #include <stdio.h> #include <stdlib.h> #include <string.h> #define _CRT_SECURE_NO_WARNINGS int ACDSort(const void *p1, const void *p2); int Compare(const void *pKey, cons