免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2819 | 回复: 3
打印 上一主题 下一主题

sun的man手册好粗心呀 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-05-11 17:02 |只看该作者 |倒序浏览
$man scandir\r\n显示\r\nSunOS/BSD Compatibility Library Functions           scandir(3UCB)\r\n\r\nNAME\r\n     scandir, alphasort - scan a directory\r\n\r\nSYNOPSIS\r\n     /usr/ucb/cc [ flag... ] file...\r\n     #include <sys/types.h>;\r\n     #include <sys/dir.h>;\r\n\r\n     int scandir(dirname, namelist, select, dcomp);\r\n     char *dirname;\r\n     struct direct *(*namelist[]);\r\n     int (*select(.),(*dcomp)();\r\n\r\n     int alphasort(d1, d2);\r\n     struct direct **d1, **d2;\r\n\r\n害得偶查半天,原来struct direct写错了,正确得应该是dirent

论坛徽章:
0
2 [报告]
发表于 2003-05-11 17:03 |只看该作者

sun的man手册好粗心呀

gcc怎么编译不通过,有大侠指点一下吗?\r\n#include <stdio.h>;\r\n#include <stdlib.h>;\r\n#include <unistd.h>;\r\n#include <errno.h>;\r\n#include <sys/types.h>;\r\n#include <dirent.h>;\r\n#include <string.h>;\r\n\r\n/*extern int scandir(const char *dirname, struct dirent ***namelist, \\\r\n   int (*select)(struct dirent *), int (*compar)(const void *, const void *));\r\n */\r\nextern int scandir(const char *dirname, struct dirent *(*namelist[]),int (*select)(struct dirent *), int (*compar)(struct dirent **, struct dirent **));\r\n\r\nextern int alphasort(const void *d1, const void *d2);\r\n\r\n/*\r\n * Select only those direntory entries that start with\r\n * \'h\'to demonstrate the selection ability :\r\n */\r\n\r\nstatic int my_select(struct dirent *dp) \r\n{\r\n  if ( dp->;d_name[0] != \'h\')\r\n    return 0; /* Don\'t include this */\r\n  return 1; /* else include this one*/\r\n}\r\n\r\n/*\r\n * Sort entries in reverse order for demonstration\r\n * purposes :\r\n */\r\nstatic int my_compar(struct dirent **d1,struct dirent **d2) \r\n{\r\n  struct dirent *dir1 = *d1;\r\n  struct dirent *dir2 = *d2;\r\n  /*\r\n   * Reverse the comparison by reversing\r\n   * dir2 with dir1 in the strcmp(3) call:\r\n   */\r\n  return strcmp(dir2->;d_name,dir1->;d_name);\r\n}\r\n\r\n/*\r\n * A good test is the direntory /etc :\r\n */\r\nint main(int argc,char **argv) \r\n{\r\n  int x; /* Work index */\r\n  int n; /* namelist[n] */\r\n  struct dirent **namelist; /* List of names */\r\n  \r\n  if ( argc < 2 ) \r\n  {\r\n    fputs(\"A pathname argument is required.\\n, Try /etc for the direntory.\\n\",stderr);\r\n    return 1;\r\n  }\r\n  \r\n  /*\r\n   * Scan the direntory given :\r\n   */\r\n  n = scandir(argv[1],&namelist,my_select,my_compar);\r\n  \r\n  /*\r\n   * Report the direntory entries :\r\n   */\r\n  printf(\"%d entries for %s:\\n\",n,argv[1]);\r\n  for ( x=0; x<n; ++x )\r\n    printf(\"%3d: %s\\n\",x,namelist[x]->;d_name);\r\n    \r\n  if ( n >; 0 ) \r\n  {\r\n    for ( x=0; x<n; ++x )\r\n      free(namelist[x]); /* Release entry */\r\n    free(namelist); /* Release the array */\r\n  }\r\n  return 0;\r\n}\r\n\r\n编译 \r\n$g++ scandir.c \r\n后返回下面的错误 \r\n\r\n未定义 文件中的 \r\n符号 在文件中 \r\nscandir(char const*, dirent***, int (*)(dirent*), int (*)(dirent**, dirent**))/var/tmp//ccdpIoK3.o \r\nld: 致命的: 符号参照错误. 没有输出被写入a.out \r\ncollect2: ld returned 1 exit status \r\n\r\n是什么错误呀?请指教。

论坛徽章:
0
3 [报告]
发表于 2003-05-11 17:37 |只看该作者

sun的man手册好粗心呀

指点一下啦,困惑中...

论坛徽章:
0
4 [报告]
发表于 2003-05-11 20:16 |只看该作者

sun的man手册好粗心呀

没#include <sys/dir.h>;
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP