本书的第一个程序,由于是在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) |