memory_replace

 

Description

Replace all occurances of certain characters in given buffer with a new character

Syntax

int memory_replace( LPSTR lpBuff, int nSize, LPSTR chOldList, int nOldListSize, char chNew )

Parameters

lpBuff
[modify] input and output buffer to replace characters with
nSize
[input] size in bytes of lpBuff
chOldList
[input] an array of bytes that we need to replace, zero is allowed
nOldListSize
[input] size of the chOldList array
chNew
[input] new character to replace any of the characters in chOldList

Return

number of characters replaced, or -1 if error happened

Examples

EX1

void memory_replace_ex1()
{
    char szTemp[10] = "A\tB\r\nC";
    char szNonePrintable[] = "\t\r\n";
    int nRet = memory_replace(szTemp, lstrlen(szTemp), szNonePrintable, lstrlen(szNonePrintable), '.');
    if(nRet)
        out_str(szTemp);
    else
        out_str("repalce failed\n");
}

Remark

See Also

header to Include

origin.h

Reference