2013-09-11 4 views
0

Windows XP 용 Visual Studio 2010을 사용합니다. 이 함수는 모든 하위 디렉토리를 인쇄하는 데 사용되지만 끔찍한 문제에 직면했습니다. 다음 코드를 참조하십시오 :하위 디렉토리 찾아보기 _finddata_t-> 이름

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 

무한 루프.

어떻게이 문제를 해결해야합니까?

+0

file_search-> name == "." C의 제 버전은 ==와 문자열 비교를 허용하지 않습니다. 어쩌면 strcmp()를 원하니? 대답 덕분에 –

답변

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

내 버전의 C는 ==와 문자열 비교를 허용하지 않습니다. 어쩌면 strcmp()를 원하니?

+0

. 지금 일하고있다. – nem0301