【发布时间】:2010-11-19 13:30:09
【问题描述】:
当我通过下面的代码列出文件时:
/*
* This program displays the names of all files in the current directory.
*/
#include <dirent.h>
#include <stdio.h>
int main(void)
{
DIR *d;
struct dirent *dir;
d = opendir(".");
if (d)
{
while ((dir = readdir(d)) != NULL)
{
printf("%s\n", dir->d_name);
}
closedir(d);
}
return(0);
}
文件是:
1. client.c
2. deneme.c
3. server.c
4. chat.h~
5. .
6. makefile~
7. udpClient.c~
8. ..
9. udpServer.cpp~
10. client
11. chat.h
12. udpServer.c~
13. server
14. makefile
15. deneme.c~
什么是数字 5. 和 8. 如果鞋那个文件名为 '.'或者 '..'。为什么会发生。有什么问题?
【问题讨论】:
-
唯一奇怪的是它们不是 1 号和 2 号。文件系统需要非常病态的实现才能将它们存储在除前 2 个目录条目之外的任何地方...