功能描述:
传入文件指针,读取文件或者字符串指定关键内容并赋值给变量:
#define PARSESTR_START \
char para_value[256]; \
const char * str_find;
#define PARSESTR_UINT8(pcBuffer, name, value) \
str_find = strstr( pcBuffer, (name) ); \
if(str_find) \
{ \
str_find += strlen( (name) ); \
sscanf(str_find, "%s", para_value); \
(value) = (unsigned char)atoi(para_value); \
}
#define PARSESTR_UINT32(pcBuffer, name, value) \
str_find = strstr( (const char *)pcBuffer, ((const char *)name) ); \
if(str_find) \
{ \
str_find += strlen( (name) ); \
sscanf(str_find, "%s", para_value); \
(value) = (unsigned int)atoi(para_value); \
}
#define PARSESTR_DOUBLE(pcBuffer, name, value) \
str_find = strstr((const char *)pcBuffer, ((const char *)name) ); \
if(str_find) \
{ \
str_find += strlen( (name) ); \
sscanf(str_find, "%s", para_value); \
(value) = (double)atof(para_value); \
}
#define PARSESTR_FLOAT(pcBuffer, name, value) \
str_find = strstr( (const char *)pcBuffer, ((const char *)name) ); \
if(str_find) \
{ \
str_find += strlen( (name) ); \
sscanf(str_find, "%s", para_value); \
(value) = (float)atof(para_value); \
}
main()
{
PARSESTR_UINT32(ptr, "关键字1", 变量1);
PARSESTR_FLOAT(ptr, "关键字2", 变量2);
PARSESTR_FLOAT(ptr, "关键字3", 变量3);
PARSESTR_FLOAT(ptr, "关键字4",变量4);
}