fread 用垃圾填充缓冲区
fread filling buffer with junk
我正在 linux 和 windows 上读取文件,在 linux 上一切正常,但在 windows 上,fread(r_hash, 1, 64 , f);
将将 64 个字符放入 r_hash,然后放入 32 个垃圾字符,我不明白为什么。这是我的代码 谢谢!
int status;
FILE *f;
char *path;
char ln[64];
char *r_hash = calloc(64, 1);
path = malloc(1024);
path = strcpy(path, "some path");
status = -1;
f = fopen(path, "rb");
if (!f)
return -1;
while (fscanf(f, "%s ", ln)!=EOF)
{
fread(r_hash, 1, 64 , f);
if(strcmp(w_hash, r_hash) == 0 && strcmp(hostname, ln) == 0)
{
status = 0;
break;
}
}
fclose(f);
r_hash = calloc(68, 1); // anything more than 64
我正在 linux 和 windows 上读取文件,在 linux 上一切正常,但在 windows 上,fread(r_hash, 1, 64 , f);
将将 64 个字符放入 r_hash,然后放入 32 个垃圾字符,我不明白为什么。这是我的代码 谢谢!
int status;
FILE *f;
char *path;
char ln[64];
char *r_hash = calloc(64, 1);
path = malloc(1024);
path = strcpy(path, "some path");
status = -1;
f = fopen(path, "rb");
if (!f)
return -1;
while (fscanf(f, "%s ", ln)!=EOF)
{
fread(r_hash, 1, 64 , f);
if(strcmp(w_hash, r_hash) == 0 && strcmp(hostname, ln) == 0)
{
status = 0;
break;
}
}
fclose(f);
r_hash = calloc(68, 1); // anything more than 64