【发布时间】:2017-08-20 18:06:09
【问题描述】:
每当我尝试在结构成员(它是一个静态字符数组)和 dirent 结构的 d_name 属性(用于读取目录)上使用 strcpy 时,我的程序都没有通过这一点。我没有收到任何错误或警告,只是没有通过它。该结构是全局初始化的。
typedef struct SearchArgs
{
char inputFile[MAXDIRPATH];
char word[MAXKEYWORD];
Buffer * buffer;
}SearchArgs;
SearchArgs * args;//arguments for seachFile
...
dir = opendir(nextItem.path);//opens the next directory
...
dp = readdir(dir);
...
printf("dname: %s\n", dp->d_name);//prints
printf("args->inputFile: %s\n", args->inputFile);//prints
strcpy(args->inputFile, dp->d_name);//not getting passed this point
printf("TEST1\n");//doesn't print
输出:
dname: file2.txt
args->inputFile: (null)
非常感谢任何见解。
【问题讨论】:
-
“没有通过这一点”是什么意思?程序是否以非零退出代码终止?
-
已更新输出。
-
@SpencerGoff。你说
args->inputFile打印正确,对吧?我在你的输出中没有看到它。 -
@FREE_AND_OPEN_SOURCE 抱歉,输出已更新。