指定位置读取bin文件中有效信息

从bin文件指定位置开始读取固定数目字符,输出打印结果

 

1、结果通过输入参数返回

#include <string.h>
#include <stdio.h>
#define tcon_path     "/data/tcon.bin"
int PANEL_TCON_BIN_VERISION(const char* tcon_bin_path, char* version){
	if (NULL == version) {
		   printf("%s:pbuf is NULL!\n", __FUNCTION__);
		   return -1;
		} 
	char str[8] = {'\0'};
	FILE* file = NULL;
	file = fopen(tcon_bin_path , "rb");
	if(!file){
	printf("tcon_bin not exit ,please check path\n");
	return -1;
	}
	fseek(file,56,SEEK_SET);
	fread(str,8,1,file);
	strcpy(version,str);
	fclose(file);
	printf ("TCON_BIN Version: %s\n",str);
	return 0;
}

int main()
{
int ret;
char version[8];
printf("start");
ret = PANEL_TCON_BIN_VERISION(tcon_path,version);
printf("ret = %d\n",ret);
printf("get str_version:%s\n",version);
return 0;
}

 

 

2、通过函数返回值返回结果

char* HAL_PANEL_TCON_BIN_VERISION(const char* tcon_bin_path){
 FILE* file = NULL;
 static char version[8];  //需要是静态类型,否则函数结束,普通局部变量就释放了
 file = fopen(tcon_bin_path , "rb");
 if(!file){
 printf("tcon_bin not exit ,please check path\n");
 return "INVALID_PATH!";
 }
 fseek(file,56,SEEK_SET);
 fread(&version,8,1,file);
 fclose(file);
 printf("TCON_BIN Version: %s",version);
 return version;
}

  

 

posted @ 2022-03-08 10:20  victorywr  阅读(221)  评论(0编辑  收藏  举报