谁可以提供机器猫的目录?---短篇

1个回答

写回答

Lu0052

2025-12-22 17:00

+ 关注

AI
AI

#include unistd.h#include dirent.h

int GetList(const char *path); // 获取某路径下所有文件

int mAIn(int argc, char *argv[]){ char *cwd;

etc
etc

if ((cwd = getcwd(NULL, 255)) == NULL) { perror(getcwd); exit(1); } (void)printf(\a当前工作路径是:%s\n, cwd); GetList(cwd);

return 0;}

int GetList(const char *path){ DIR *dir; struct dirent *ptr; if( (dir=opendir(path))==NULL ) { perror(opendir error); return -1; }

while( (ptr=readdir(dir))!=NULL ) { printf(ptr.name = %s\n, ptr-d_name); } closedir(dir);

return 0;}

举报有用(0分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号