日期:2014-05-16  浏览次数:20747 次

关于unix高级编程的一个例子
#include "apue.h"
#include <dirent.h>

int
main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;

if (argc != 2)//请问此处的if(argc!=2)是什么意思?
err_quit("usage: ls directory_name");

if ((dp = opendir(argv[1])) == NULL)
err_sys("can't open %s", argv[1]);
while ((dirp = readdir(dp)) != NULL)
printf("%s\n", dirp->d_name);

closedir(dp);
exit(0);
}


------解决方案--------------------
int main(int argc, char **argv)
argc ---argument count 参数个数
argv----argument vector 参数内容组成的指针数组
举例: ./main you can try
argc = 4
argv[1] = "./main"
argv[2] = "you"
........