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] = ...
| c++ comp.lang.c++ usenet archive |
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| // 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 |
![]() |
| Thread Tools | |
| |
| ||||
| 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 |


