Chinaunix首页 | 论坛 | 博客
  • 博客访问: 278672
  • 博文数量: 101
  • 博客积分: 4245
  • 博客等级: 上校
  • 技术积分: 1085
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-24 00:28
文章分类

全部博文(101)

文章存档

2012年(1)

2011年(16)

2010年(34)

2009年(50)

我的朋友

分类: LINUX

2011-05-05 16:27:52

本书的第一个程序,由于是在linux环境下的程序,好多东西都不熟悉:
需要哪些头文件?有哪些数据类型?这些数据类型在哪个头文件里面定义。。。。。。。
 
exit(0)表示正常终止一个程序,1-255表示错误发生
 
•int main(int argc, char *argv[])这种形式的主函数中,argc表示命令行的参数个数,argv[]代表每个参数的字符串。
•DIR represents a directory stream.是在dirent.h中定义的:
•[test@manager ~]$ grep 'DIR;$' /usr/include/dirent.h
typedef struct __dirstream DIR;

 
 
linux下遍历目录的一般方法是:opendir -> readdir -> closedir
 
SYNOPSIS
       #include
       #include
       DIR *opendir(const char *name);
 
NAME
       readdir - read a directory
 
SYNOPSIS
       #include
       #include
       struct dirent *readdir(DIR *dir);
DESCRIPTION
       The  readdir()  function  returns  a  pointer to a dirent structure representing the next directory entry in the directory stream pointed to by dir.  It
       returns NULL on reaching the end-of-file or if an error occurred.
       On Linux, the dirent structure is defined as follows:
          struct dirent {
              ino_t          d_ino;       /* inode number */
              off_t          d_off;       /* offset to the next dirent */
              unsigned short d_reclen;    /* length of this record */
              unsigned char  d_type;      /* type of file */
              char           d_name[256]; /* filename */
          };
       According to POSIX, the dirent structure contains a field char d_name[] of unspecified size, with at most NAME_MAX characters preceding the  terminating
       null byte.  POSIX.1-2001 also documents the field ino_t d_ino as an XSI extension.  Use of other fields will harm the portability of your programs.
       The data returned by readdir() may be overwritten by subsequent calls to readdir() for the same directory stream.
阅读(1596) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~