网上资源真很多, 我都不知为了解决一个问题都要花多长时间, 都快到放弃的心, 可都坚持 , 学习编程都是要一个人去解决问题, 没有人讨论, 也没人去问, 找不到人去问.
http://qq164587043.blog.51cto.com/261469/90413
/************************************************************
系统结构
struct stat {
_dev_t st_dev;
_ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
_off_t st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
};
********************************************************/
/* @_@求文件属性. 文件大小等 */
#include <stdio.h>
#include <process.h>
#include <fcntl.h>
# include <io.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/stat.h>
#if 0
long file_size(const char * filename)
{
struct stat st;
if (stat((char * )filename, &st) < 0)
return 0;
return (long)st.st_size;
}
void main( void )
{
printf("%d \n", file_size("tet.c"));
}
#else
#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
int main()
{
struct stat *buf = NULL;
buf = (struct stat *)malloc(sizeof(struct stat));
if(stat("tet.c", buf) == -1)
{
perror("stat error!\n");
exit(1);
}
printf("file type :%d\n", buf->st_mode);
printf("i-node num :%d\n", buf->st_ino);
printf("dev num(firstsystem) :%d\n", buf->st_dev);
printf("dev num(special) :%d\n", buf->st_rdev);
printf("link numbers :%d\n", buf->st_nlink);
printf("uid :%d\n", buf->st_uid);
printf("gid :%d\n", buf->st_gid);
printf("uid :%d\n", buf->st_uid);
printf("gid :%d\n", buf->st_gid);
printf("size in bytes :%d\n", buf->st_size);
printf("last access time :%d\n", buf->st_atime);
printf("last modification time :%d\n", buf->st_mtime);
printf("last status change time :%d\n", buf->st_ctime);
return 0;
}
#endif;