执行fread函数成功后,返回的值是等于data_len。但是执行strlen后,字符串buff的长度不对。但是我用fwrite将图片写到另一个.jpg是OK的
int main()
{
FILE *fp,*out;
int c,len;
out=fopen("out.jpg","wb");
if((fp=fopen("/home/jens/Desktop/picture.jpg","rb"))<0){
printf("error open\n");
}
if(fp == NULL)
printf("Open file Error!");
fseek(fp,0,SEEK_END);
int data_len=ftell(fp);
printf("datalen %d",data_len);
rewind(fp);
char* buff=(char *)malloc((data_len)*sizeof(char)+1);
size_t a=fread(buff,sizeof(char),data_len,fp);
printf( "\n a %d",a); //a的值是图片的大小
len=strlen(buff);
printf("\n len %d",len);//在这里buff的大小却只是4。
char* HTTP_INFO=(char *)malloc((data_len)*sizeof(char)+1024);
char *buf="abcdefg";
printf("\n %d",strlen(buf));
len=sprintf(HTTP_INFO,"%s",buf);//如果把这个换成buff,结果也还是4。
printf("\nlen %d",len);
fclose(fp);
fclose(out);
return 0;
}
运行的结果如下图