【发布时间】:2011-11-01 02:56:37
【问题描述】:
看我的代码是
#include <stdio.h>
#include<stdlib.h>
#include<sys/stat.h>
int main(int argc, char**argv) {
unsigned char *message = NULL;
struct stat stp = { 0 };
stat("huffman.txt", &stp);
/*determine the size of data which is in file*/
int filesize = stp.st_size;
printf("\nFile size id %d\n", filesize);
FILE* original_fileptr = fopen("huffman.txt", "r");
message = malloc(filesize);
fread(message, 1, filesize, original_fileptr);
printf("\n\tEntered Message for Encode is %s= and length %d", message,strlen(message));
return 0;
}
这里 huffman.txt 的大小为 20 字节,并且有以下字符
άSUä5Ñ®qøá"F„œ
这段代码的输出是
File size id 20
Entered Message for Encode is άSUä5Ñ®qøá"F„œ= and length 21
现在的问题是如果 size 是 20 那么为什么 length 是 21 ?
【问题讨论】:
标签: c