我想存储pointers已经使用被分配malloc()在array再free毕竟他们.然而,即使该程序没有抱怨它不起作用.下面cleanMemManager()实际上free没有内存,因为在main()char*中测试时pointer没有NULL,它将打印???.
码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void **ptrList = NULL;
void tfree(void** ptr)
{
free(*ptr);
*ptr = NULL;
}
void* talloc(int size)
{
void* ptr = malloc(size);
ptrList[0] = ptr; ///No clue if this actually does what I think it does
return ptrList[0];
}
void initMemManager()
{
ptrList = (void**)malloc(sizeof(void**) * 3);
memset(ptrList, 0, sizeof(void**) * 3);
} …Run Code Online (Sandbox Code Playgroud) 我想查找员工的详细信息,如果他有A和B类型的信用卡.
表结构类似{empid, ccno, cctype},假设empid'e1'具有所有卡类型.
我试过类似的东西
select * from test where cctype = all('A', 'B') and empid = 'e1'
Run Code Online (Sandbox Code Playgroud)
但这并没有返回任何行.
你能解释我为什么错吗?任何帮助表示赞赏.提前致谢.
我试图简单地在MongoDB集合中插入一个条目Nodejs.这是我的代码:
码:
const MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/TodoApp', (err, db) => {
if (err) {
return console.log('Unable to connect to MongoDB server');
}
console.log('Connected to MongoDB server');
db.collection('Todos').insertOne({
text: 'Something to do',
completed: false
}, (err, result) => {
if (err) {
return console.log('Unable to insert todo', err);
}
console.log(JSON.stringify(result.ops, undefined, 2));
});
db.close();
});
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,它显示以下错误:
错误:
TypeError: db.collection is not a function
Run Code Online (Sandbox Code Playgroud) 我有3个 variable
print(obj.col1_expense.text) #test1
print(obj.col2_expense.text) #test2
print(obj.col3_expense.text) #test3
Run Code Online (Sandbox Code Playgroud)
如何打印动态?现在我想这样做
for x in range(1, 4):
print("obj.col"+str(x)+"_expense".text)
Run Code Online (Sandbox Code Playgroud)
但它给出了错误.
AttributeError: 'str' object has no attribute 'text'
Run Code Online (Sandbox Code Playgroud)