[原创]学习UNIX下的C编程(一)
写此文的目的是为了帮助想在UNIX环境下学习编程的朋友,大家互相交流,共同进步
从基础学起,
一、UNIX下的文件系统
UNIX文件系统是目录和文件的一种层次安排、目录的起点称为根(root).用字符“/”来表示
目录实质上是一个包括目录项的文件。对于不同的磁盘分区安排不同的挂载点,所以在UNIX 里没有什么C盘D盘的概念,这一点与windows系统有着本质的区别。
这里是一个列出文件和目录名的小程序,供大家参考
注:这里不再讲述C语言本身,而注重UNIX环境。
/*
* list the directory and file,it like the "DIR" command for windows
* author:xinhe
*/
#include
#include
#include
int main(int argc,char **argv)
{
DIR *p;
struct dirent *dirp;
if(argc!=2)
{
printf("usage:dir directory");
exit(1);
}
if((p=opendir(argv[1]))==NULL)
{
printf("can't open %s",argv[1]);
exit(1);
}
while((dirp=readdir(p))!=NULL)
printf("%s\n",dirp->d_name);
close(p);
exit(0);
}
[URL=http://bbs.xplore.cn][IMG]http://www.xplore.cn/sign_xinhe.gif[/IMG][/URL]
[color=#ff0000]这人一到了大学就要写程序,过去用ASP,一天三遍的写,麻烦!现在有了PHP,一行顶过去五行,方便!PHP效率不错还挺实惠。[/color]