Hello I need your help to convert void* (hex number) to decimal number. I use sqlite3 in my code and the callback function give me a &data that contains number of row. the problem is: I need to save &data (hex number) as int. maybe there is another way to do this but I try to convert the &data hex to decimal int and the issue is to convert the void*. I try to convert the void* to int but the Running time problem to get the pointer. I will be happy if you help me do the conversion. Thanks.
some code -
void* data = nullptr;
rc = sqlite3_exec(db, str.data(), callback, &data, &zErrMsg);
int id = 0;
if (data != nullptr)
{
int dataa = *((int *)data); // run time error
istringstream(dataa) >> std::hex >> id; \\ istringstream can't convert void* // NEED CHANGE
}
return id;
callback function -
if (argc == 0) {
user_exist = false; return 0;
}
else {
user_exist = true;
if (notUsed != NULL) {
cout << argv[0] << endl;
((int)notUsed) = atoi(argv[0]);
}
}
return 0;
sqlite3_exec()
is useful only when you can actually handle the data in the callback. In practice, you should normally use the sqlite3_prepare_v2() / sqlite3_step() / sqlite3_finalize() functions to read data:
sqlite3_stmt *stmt;
int rc = sqlite3_prepare_v2(db, "SELECT ...", -1, &stmt, NULL);
if (rc != SQLITE_OK) {
print("error: ", sqlite3_errmsg(db));
return -1;
}
rc = sqlite3_step(stmt);
if (rc != SQLITE_ROW && rc != SQLITE_DONE) {
print("error: ", sqlite3_errmsg(db));
} else {
user_exist = rc == SQLITE_ROW;
}
sqlite3_finalize(stmt);
(For most other queries, you would call the sqlite3_column_*() functions to read the actual values, as long as you get SQLITE_ROW
.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.