I created a dyanamic array through malloc() function.
(size is 1024)

next time i want to change buffersize as 500 . how

can do this?

Recommended Answers

All 4 Replies

malloc(500)

Did you do any research at all? It's not like C has so many functions in the standard library that realloc is hard to locate.

if(bRangeValid == TRUE)
        {

// pszReplace is malloc array
            // function calling
            pszReplace = StrReplaceString(*ppszLine, pCmdList->szFirstArgument, 
                pCmdList->szSecondArgument);

            // check string null or not
            if(pszReplace != NULL)
            {
                // length of replaced string
                nStringLen = (int) _mbstrlen(pszReplace);

                                      // free(ppszLine); this is also a malloc array     error come here i wnat ot remoce this error

                // realloc memory
                *ppszLine = realloc( *ppszLine, nStringLen + 1);

                // check memory is null or not
                if(*ppszLine == NULL)
                {
                    return (0);
                }

                // for store replaced string into pszLine
                _mbscpy(*ppszLine, pszReplace);

                // free the memory
                free(pszReplace);
            }
        }

// Actually ithink we dont want to free the buffer before using realloc
if(bRangeValid == TRUE)
{

// pszReplace is malloc array
// function calling
pszReplace = StrReplaceString(*ppszLine, pCmdList->szFirstArgument,
pCmdList->szSecondArgument);

// check string null or not
if(pszReplace != NULL)
{
// length of replaced string
nStringLen = (int) _mbstrlen(pszReplace);

// realloc memory
*ppszLine = realloc( *ppszLine, nStringLen + 1);

// check memory is null or not
if(*ppszLine == NULL)
{
return (0);
}

// for store replaced string into pszLine
_mbscpy(*ppszLine, pszReplace);

// free the memory
free(pszReplace);
}
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.