Home > Back-end >  Pointer array problem...
Pointer array problem...

Time:03-05

C + + pointer to learn, ask a question,

 
Boolean fun (char * pszPath)
{
Char szFileList [] [MAX_PATH * 2]={0};
Int iNum=searchFile (pszPath szFileList [] [MAX_PATH * 2]).

//processing after the completion of the memory how to safely release

}

Int searchFile (char * pszDirectory, char szFileList [] [MAX_PATH * 2])
{
.
//find file
Char szFindFileName [MAX_PATH * 2]={0};
//find szFindFileName file name, how to join szFileList, return
.

//return the number of files to find the
Return inum;
}

CodePudding user response:

, the size of the array, seemingly can't use variables to a constant, 10100, for example, if you MAX_PATH is pre-defined, but can't * 2, after such definition, an array of memory automatic release,

CodePudding user response:

After a predefined MAX_PATH, such definition no problem, the space allocated on the stack, function returns automatically to release the
Char szFileList [] [MAX_PATH * 2]={0};
Alright with this definition function
Int searchFile (char * pszDirectory, char szFileList [] [MAX_PATH * 2])
Can be defined as
Int searchFile (char * pszDirectory, char * * szFileList)

CodePudding user response:

Semantically I don't understand why want to add szFindFileName szFileList,
But you really need it, to a free line is found in szFileList then strcpy inside,

CodePudding user response:

Hit the submit button
Strcpy (szFileList [I], szFindFileName);
If you know what that line free or available,

CodePudding user response:

refer to the second floor gouyanfen response:
predefined MAX_PATH, this definition is no problem, the space allocated on the stack, function returns automatically to release the
Char szFileList [] [MAX_PATH * 2]={0};
Alright with this definition function
Int searchFile (char * pszDirectory, char szFileList [] [MAX_PATH * 2])
Can be defined as
Int searchFile (char * pszDirectory, char * * szFileList)


Function definition there is no problem...

CodePudding user response:

You should be similar to traverse the function of the catalog file, you can use a list or the vector
Struct
{
Long filesize.
Char filename [128].
.

} findfile;
The vector & lt; Fildfile * & gt; User_file_list;
Int searchFile (char * pszDirectory, vecotor * findfile szFileList)

reference 5 floor wula0010 reply:
Quote: refer to the second floor gouyanfen response:
predefined MAX_PATH, this definition is no problem, the space allocated on the stack, function returns automatically to release the
Char szFileList [] [MAX_PATH * 2]={0};
Alright with this definition function
Int searchFile (char * pszDirectory, char szFileList [] [MAX_PATH * 2])
Can be defined as
Int searchFile (char * pszDirectory, char * * szFileList)


Function definition there is no problem...

Even if no problem, you need internal back to content, must be defined as a pointer
  • Related