0

I have a function which takes a path and some other stuff. The function is used to go through directories and if there's another directory it should open that one as well. The problem I have is when I recursively call the function. Sorry for lack of information but I don't think more is needed. So when I recursively call my function it looks like this:

func(realpath(pDirent->d_name, buff), name, ...(flags)...);

where name is a the file I am looking for and pDirent->d_name is the name of the folder which I now want to continue my search for the file, name.

And now to the problem. When I just send in realpath(pDirent->d_name, buff) it doesn't work. So I think I need to add the pDirent->d_name to my current path. I have looked around but I didn't find any way to do this. Essentially what I wanna do is add a "/" + pDirent->d_name to my path string. Is there any function that will get this done?

AndyG
  • 39,700
  • 8
  • 109
  • 143
Fjodor
  • 529
  • 1
  • 7
  • 19
  • What does not work, show more code. Maybe you look for the `strcat` function. – Jabberwocky Oct 21 '14 at 15:03
  • 1
    We don't know types of variables... nothing. We can't make an accurate judgment. Please check here: http://stackoverflow.com/questions/308695/how-to-concatenate-const-literal-strings-in-c – SlySherZ Oct 21 '14 at 15:04
  • void func(char *path, char *name,... – Fjodor Oct 21 '14 at 15:07
  • `char path[256]="/";func(strcat(path, realpath(pDirent->d_name, buff)), ...` – BLUEPIXY Oct 21 '14 at 15:46
  • Don't tinker with the path or file names passed to the recursive function, work with local copies, or you will corrupt names that may still be needed by the calling instance of the function. – Weather Vane Oct 21 '14 at 17:02

1 Answers1

0

the function you want is realloc() http://www.cplusplus.com/reference/cstdlib/realloc/. It will resize your array, while leaving its contents intact.

ragingSloth
  • 1,094
  • 8
  • 22