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

next time i want to change buffersize as 500 . how

can do this?

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);
            }
        }

Edited 3 Years Ago by Nick Evan: Fixed formatting

// 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);
}
}

This article has been dead for over six months. Start a new discussion instead.