char *buf = malloc(123)
再访问buf
在嵌入式或者单片机中,有时会访问绝对地址
unsigned char * p = (unsigned char *)0xB1234456//内存地址值
然后通过*p访问该地址。
你好,代码如下:char *readfile(char *path)
{
FILE *fp
int length
char *ch
if((fp=fopen(path,"r"))==NULL)
{
printf("open file %s error.\n",path)
exit(0)
}
length=filelength(fp)
ch=(char *)malloc(length)
fread(ch,length,1,fp)
*(ch+length-1)='\0'
return ch
}
int filelength(FILE *fp)
{
int num
fseek(fp,0,SEEK_END)
num=ftell(fp)
fseek(fp,0,SEEK_SET)
return num
}
希望可以帮到你。