Glob在C ++和打印结果

编程入门 行业动态 更新时间:2024-10-25 16:21:10
本文介绍了Glob在C ++和打印结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我只是想在一个目录中的glob一切,并打印结果的列表,但我得到一个空printf:

I'm just trying to glob everything in a directory and print the list of results, but I get an empty printf:

#include <glob.h> #include <stdio.h> int main() { int result; glob_t buffer; buffer.gl_offs = 10; glob("*", GLOB_DOOFFS, NULL, &buffer); printf((char*)buffer.gl_pathv); }

这是什么工作

printf("%i", buffer.gl_pathc));

推荐答案

如果您不需要它,请不要包括 GLOB_DOOFFS 。 不要忘记为glob存储空间。

Do you need to reserve empty slots in glob? Do not include GLOB_DOOFFS if you don't need it. And don't forget to free memory for glob.

尝试这样:

#include <glob.h> #include <stdio.h> int main() { glob_t globbuf; int err = glob("*", 0, NULL, &globbuf); if(err == 0) { for (size_t i = 0; i < globbuf.gl_pathc; i++) { printf("%s\n", globbuf.gl_pathv[i]); } globfree(&globbuf); } return 0; }

更多推荐

Glob在C ++和打印结果

本文发布于:2023-10-07 14:40:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469661.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Glob

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!