0

我将 Visual Studio 2010 用于 Windows XP。此功能用于打印所有子目录,但我面临着可怕的问题。请参见以下代码:

typedef struct _finddata_t FILE_SEARCH;

void fileListPrint(char* path, FILE_SEARCH* file_search, int deep){ 
intptr_t h_file;
int i, isForD;
char cwd[256];
char* temp = path;  
FILE_SEARCH fileSearch;

temp = (char*)malloc(256);

for(i=0; i<strlen((path)); i++)
{
    temp[i] = path[i];
}
temp[i-3] = '\0';


if((h_file = _findfirst(path, file_search)) == -1L)
    errorHandling("doesn't exist file\n");


printf("[%s] 출력 [%d] 깊이 \n", path, deep);
do
{       
    printf("%s\n", file_search->name);              
    isForD = isFileOrDir(strncat(temp, file_search->name,sizeof(temp) + sizeof(file_search->name)));        
    printf("%d\n", isForD);

    temp[i-3] = '\0';       

    if(file_search->name == ".")
        printf("same\n");
    else
        printf("diff\n");

    if(0 == isForD)
    {                   
        strncat(temp, "\\*.*", sizeof(temp) + 5);
        Sleep(1000);
        fileListPrint(temp, &fileSearch, deep+1);                       
        temp[i-3] = '\0';       }
    else if(1 == isForD)
    {
        temp[i-3] = '\0';       
        continue;
    }
    else if(file_search->name == ".")
    {
        temp[i-3] = '\0';       
        break;
    }



}while(_findnext(h_file, file_search) == 0);

_findclose(h_file);

free(temp);
}

我试图理解这个代码片段:

 if(file_search->name == ".")
        printf("same\n");
    else
        printf("diff\n");

为什么不一样?

打印打印结果:

[D:\*.*] 출력 [0] 깊이
.
0
diff
[D:\1\*.*] 출력 [1] 깊이
.
0
diff
[D:\1\.\*.*] 출력 [2] 깊이
.
0
diff
[D:\1\.\.\*.*] 출력 [3] 깊이
.
0
diff

无限循环。

我应该如何解决这个问题?

4

1 回答 1

1
if(file_search->name == ".") 

我的 C 版本不允许与 == 进行字符串比较。也许你想要 strcmp() ?

于 2013-09-11T01:32:59.120 回答