API 获取文件某个字段对应的整型值

来源:互联网 发布:java租车系统代码 编辑:程序博客网 时间:2024/06/05 03:30
获取文件某个字段对应的整型值 key:value
long long get_file_key_integer_value(const char * path, const char *key){FILE *fp;char buf[512];char *p_dst = NULL;char *p_rx = NULL;long long result = 0;if(NULL == path || NULL == key){printf("file path is null or the key is null\n");return -1;}fp = fopen(path,"r");if(!fp){perror("fopen\n");return -1;}while(fgets(buf,sizeof(buf),fp)){p_dst = strstr(buf,key);if(p_dst){p_rx = strstr(p_dst,":");if(p_rx == NULL){fclose(fp);return -1;}result = strtoll(p_rx+1,NULL,10);//printf("[get_file_key_integer_value] %s = %lld\n",key,result);fclose(fp);return result;}}fclose(fp);return -1;}

阅读全文
0 0
原创粉丝点击