C função de retorno de seqüência de caracteres retorna lixo

Estou tendo problemas para retornar uma string de uma função. Imprime um valor de lixo no método principal. Eu vi uma pergunta semelhante neste fórum, mas os resultados nessa página não me ajudaram. Eu não quero passar outra variável para a função. Eu quero ser capaz de retornar o valor da seqüência como é. Como posso fazer isso?

<pre><code>char *LookupPath(char **argv, char **dir) { /* String Name To Be Returned */ char path_name[MAX_PATH_LEN] = {0}; char *result = malloc(sizeof(path_name)); int i; /* Check To See If File Name Is Already An Absolute Path Name */ if(*argv[0] == '/') { } /* Look In Path Directories */ for(i = 0; dir[i] != NULL; i++) { strncat(path_name, dir[i], sizeof(path_name)); strncat(path_name, "/", sizeof(path_name)); strncat(path_name, argv[0], sizeof(path_name)); result = path_name; if(access(result, F_OK) == 0) { printf("result: %s\n", result); return result; } path_name[0] = '\0'; } /* File Name Not Found In Any Path Variable */ return NULL; } </code></pre>

Sua ajuda é muito apreciada!

questionAnswers(4)

yourAnswerToTheQuestion