#include <stdio.h>
#include <pjlib.h>
#include <pj/types.h> // for pj_init.
#define THIS_FILE "main.c"
/*
数组测试
*/
void array_test(void);
static pj_status_t matching_cb(const void *value);
int main(int argc, char** argv)
{
pj_status_t status;
// pjlib库初始化
status = pj_init();
if (status != PJ_SUCCESS)
{
char errmsg[PJ_ERR_MSG_SIZE];
pj_strerror(status, errmsg, sizeof(errmsg));
PJ_LOG(1,(THIS_FILE, "%s: %s [status=%d]", pj_init, errmsg, status));
return -1;
}
// 数组测试
array_test();
// pjlib库关闭
pj_shutdown();
return 0;
}
/*
数组测试
*/
void array_test(void)
{
char a = '@';
char* p = NULL;
char array[32] = "abc123";
PJ_LOG(3, (THIS_FILE, "array = %s", array));
// 向数组中特定位置插入一个元素
pj_array_insert(array, sizeof(char), (unsigned)strlen(array), 3, &a);
PJ_LOG(3, (THIS_FILE, "array = %s", array));
// 删除数组中特定位置的一个元素
pj_array_erase(array, sizeof(char), (unsigned)strlen(array), 3);
array[strlen(array)-1] = '\0';
PJ_LOG(3, (THIS_FILE, "array = %s", array));
// 查找数组中的特定元素
pj_array_find(array, sizeof(char), (unsigned)strlen(array), matching_cb, &p);
}
static pj_status_t matching_cb(const void *value)
{
char *p = (char*)value;
PJ_LOG(3, (THIS_FILE, "*p = %s", p));
// 具体匹配的代码需要自行编写
return PJ_SUCCESS;
}