Objectmix
Tags Register Mark Forums Read

call function with char** as parameter; Memory issue : c++

This is a discussion on call function with char** as parameter; Memory issue within the c++ forums in Programming Languages category; I call a function with a parameter 'char**' and the parameter is amemory allocated within the function. The problem isi that the allocation is lasted only within the scope of the function and not after the return. Code follows: // tha global declaration const char **pszCriteria = NULL; // function definition, looks good through the debugger int GetCriteria(char **pszCriteria) { ... // get allocation for the number of char* (the rows of char**) pszCriteria = malloc(nLines * sizeof *pszCriteria); for (j = 0; j < nLines ; j++) { ... // and now get allocation for each char* pszCriteria[j] = ...


Object Mix > Programming Languages > c++ > call function with char** as parameter; Memory issue

c++ comp.lang.c++ usenet archive

Reply

 

LinkBack Thread Tools
  #1  
Old 04-08-2009, 06:17 AM
Junior Member
 
Join Date: Apr 2009
Posts: 0
Sunscrenn is on a distinguished road
Default call function with char** as parameter; Memory issue

I call a function with a parameter 'char**' and the parameter is amemory allocated within the function. The problem isi that the allocation is lasted only within the scope of the function and not after the return. Code follows:

// tha global declaration
const char **pszCriteria = NULL;

// function definition, looks good through the debugger
int GetCriteria(char **pszCriteria)
{

...

// get allocation for the number of char* (the rows of char**)
pszCriteria = malloc(nLines * sizeof *pszCriteria);

for (j = 0; j < nLines ; j++)
{
...

// and now get allocation for each char*
pszCriteria[j] = malloc(strlen(szLine) + 1);

// and use it
strncat(pszCriteria[j], szLine, strlen(szLine) - 1);
}

return nLines;
}

int main()
{

...

// and now the call
nLines = GetCriteria(*(&pszCriteria));

// now scan the file and return each count
for (n = 0; n < nLines; n ++)
{
m = Scan3(word, pszCriteria[n]); // UHANDLED ERROR - possibly memory issue

...
}

return 0;

}

Any ideas?

Thanks in advance,
Sun
Reply

Thread Tools


Similar Threads

Thread Thread Starter Forum Replies Last Post
Calling DLL function from C# and char** parameter type usenet CSharp 11 01-17-2008 09:43 PM
Calling DLL function from .NET and char** parameter type usenet DOTNET 5 01-16-2008 05:13 PM
string or const char * in a function parameter list ? usenet c++ 3 08-23-2007 08:23 AM
Passing C# string to unmanaged C++ function const char* input parameter usenet DOTNET 1 06-30-2006 01:46 AM
Passing byte[] parameter (c#) as unsigned char* (C++) into interop function usenet DOTNET 3 05-26-2006 01:20 PM


All times are GMT -5. The time now is 08:38 AM.

Managed by Infnx Pvt Ltd.