Funkcja powrotu ciągu C Zwraca śmieci

Mam problem z zwróceniem ciągu znaków z funkcji. Wypisuje wartość śmieci w głównej metodzie. Widziałem podobne pytanie na tym forum, ale wyniki na tej stronie mi nie pomogły. NIE chcę przekazywać innej zmiennej do funkcji. Chcę móc zwracać wartość ciągu w takiej postaci, w jakiej jest. Jak mogę to zrobić?

<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>

Twoja pomoc jest bardzo mile widziana!

questionAnswers(4)

yourAnswerToTheQuestion