69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string.h>
#include <conio.h>
FILE *fi,*fo;
unsigned int n;
int c;
//-------------------------------------------------------
void main(int argc,char *argv[])
{
if (argc<3) {
cprintf("Bin2Hex srcfile desfile");
return;
}
if ((fi=fopen(argv[1],"rb"))==NULL) {
cprintf("Can not find file %s",argv[1]);
return;
}
if ((fo=fopen(argv[2],"w"))==NULL) {
fclose(fi);
cprintf("Can not create file %s",argv[2]);
return;
}
n=0;
while (1) {
c=fgetc(fi);
if (EOF==c) break;
n++;
if (1==n) fprintf(fo, "0x%02X",c);
else {
if (1==n%16) fprintf(fo,"\n0x%02X",c);
else fprintf(fo, ",0x%02X",c);
}
}
fcloseall();
cprintf("OK to Bin2Hex %u bytes.",n);
}
fscanf(fp, "%c%c%c", &temp_data[0], &temp_data[1], &temp_data[2]);
替换为:
fread(&temp_data, 3, 1, fp);
#include <stdio.h>
#include <stdlib.h>
typedef struct _data_array
{
int a;
char b;
} DATA_ARRAY;
int main(int argc, char **argv)
{
DATA_ARRAY arrays[1024];
FILE *fp = NULL;
char temp_data[3] = { 0 };
int i = 0;
fp = fopen("your path", "b");
if (fp == NULL)
return -1;
for (i = 0; i < 1024 && !feof(fp); i ++)
{
fscanf(fp, "%c%c%c", &temp_data[0], &temp_data[1], &temp_data[2]);
arrays[i].a = temp_data[1] << 8 + temp_data[0];
arrays[i].b = temp_data[2];
}
return 0;
}
#include <stdio.h>
#include <fcntl.h>
#include <malloc.h>
#include <io.h>
#include <errno.h>
#include<string.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
#include <fcntl.h>
#include <malloc.h>
#include <io.h>
#include <errno.h>
#define DEST_FILE "1.h"
#define SRC_FILE "1.bin"
1
int main(void)
{
FILE* fpSrc;
Int32 fpSrcTmp,fpDest;
Int32 fpDestStm;
char *array = "static const S_Config_first[] = \n{";
if(!(access(DEST_FILE,0)<0))
{
system("1.h -R");
remove("1.h");
}
if((fpSrcTmp = open(SRC_FILE, O_RDONLY | O_BINARY)) == -1)
{
puts("1.bin 不存在,按任意键退出");
getch();
return 0;
}
close(fpSrcTmp);
fpDest = open("1.h", O_RDWR|O_BINARY|O_CREAT);
if(fpDest==-1)
{
printf("errno=%d\n",errno);
puts("创建文件失败1.h,请重新尝试,按任意键退出!");
getch();
return 0;
}
fpSrc = fopen(SRC_FILE,"r");
while(!feof(fpSrc))
{
}
我写到这里就不会写了