设为首页
收藏本站
用户名
Email
自动登录
找回密码
密码
登录
注册
快捷导航
平台
Portal
论坛
BBS
文库
项目
群组
Group
我的博客
Space
搜索
搜索
热搜:
shell
linux
mysql
本版
用户
LinuxSir.cn,穿越时空的Linuxsir!
»
论坛
›
编程开发讨论区 —— LinuxSir.cn
›
Linux 程序设计专题讨论
›
文件大小属性
返回列表
查看:
636
|
回复:
1
文件大小属性
[复制链接]
neighborinfo
neighborinfo
当前离线
积分
30
IP卡
狗仔卡
发表于 2005-11-29 15:02:31
|
显示全部楼层
|
阅读模式
您好!请教个问题:
>if(stat("/etc/fstab",&statbuf)==-1)
>{
> printf("Get stat on %s Error:%s\n","/etc/fstab",strerror(errno));
> return -1;
>}
>printf("file size:%ld bytes\n",statbuf.st_size);
>
>我用这段代码读取文件大小属性,我试过好几个文件,读出来的结果都是1,请问为什
>么?我这样做对吗?
>谢谢!
回复
使用道具
举报
提升卡
置顶卡
沉默卡
喧嚣卡
变色卡
显身卡
haohao_h
haohao_h
当前离线
积分
366
IP卡
狗仔卡
发表于 2005-11-29 19:09:15
|
显示全部楼层
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/**@
*ident
*
*
* */
int main(int argc, char *argv[])
{
struct stat buf;
stat("/etc/fstab",&buf);
printf("size is %d\n", buf.st_size);
return 0;
}
复制代码
结果
debian:/home/hedes/test# ./test
size is 367
复制代码
回复
支持
反对
使用道具
举报
显身卡
返回列表
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
注册
本版积分规则
发表回复
回帖后跳转到最后一页
Copyright © 2002-2023
LinuxSir.cn
(http://www.linuxsir.cn/) 版权所有 All Rights Reserved.
Powered by
RedflagLinux!
技术支持:
中科红旗
|
京ICP备19024520号
快速回复
返回顶部
返回列表