请c语言高手帮忙解决错误?

来源:百度知道 编辑:UC知道 时间:2024/06/11 07:03:01
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <malloc.h>
#include <time.h>

void main()
{
struct _stat b;
FILE *fp;

if((fp = fopen("D:\\a.txt","r")) == NULL)
{
printf("can not find the file ! \n");
exit(0);
}

_stat("stat.c", &b);

printf("%d",b.st_size);
printf("\n");

}
这里面的哪里出错了,为什么测出来是个负数?

_stat("stat.c", &b); 你是想求文件的信息吧?如果是这样的话,那么_stat()的第一个参数应该是包含文件路径及文件名的字符串,你这里用的stat.c这个文件存在吗?我觉得应该是_stat(("D:\\a.txt", &b); 这样才可以。

你那结构体是什么啊~