Chaging Characters;
-
How do I change the value at certain positions in a TCHAR*? If I do.. TCHAR* pStr = _T("Bo Hunter"); pStr[pos] = _T('O'); it breaks with access violation. If I do.. TCHAR szStr[MAX_SIZE] = {0}; lstrcpy(szStr, _T("Bo Hunter")); szStr[pos] = _T('O'); it works. Thank You Bo Hunter
-
How do I change the value at certain positions in a TCHAR*? If I do.. TCHAR* pStr = _T("Bo Hunter"); pStr[pos] = _T('O'); it breaks with access violation. If I do.. TCHAR szStr[MAX_SIZE] = {0}; lstrcpy(szStr, _T("Bo Hunter")); szStr[pos] = _T('O'); it works. Thank You Bo Hunter
pStr[pos] = _T('O'); shouldnt it be *pStr[pos] = _T('O'); or *(pStr + pos) = _T('O'); My God is more powerfull Than Your God. (the line that divides the world)
-
pStr[pos] = _T('O'); shouldnt it be *pStr[pos] = _T('O'); or *(pStr + pos) = _T('O'); My God is more powerfull Than Your God. (the line that divides the world)
I tried all of that before. // Illegal indirection *pStr[pos] = _T('O'); // Access violation writing location 0x0049924d. *(pStr + pos) = _T('O'); I am within the bounds of the string for sure. pStr starts at 0x0049924c I thought for sure that *(pStr + pos) = 'O'; was wright. Thank You Bo Hunter
-
How do I change the value at certain positions in a TCHAR*? If I do.. TCHAR* pStr = _T("Bo Hunter"); pStr[pos] = _T('O'); it breaks with access violation. If I do.. TCHAR szStr[MAX_SIZE] = {0}; lstrcpy(szStr, _T("Bo Hunter")); szStr[pos] = _T('O'); it works. Thank You Bo Hunter
Bo Hunter wrote: TCHAR* pStr = _T("Bo Hunter"); Now
pStr
holds the adress of the constant string somwhere in the code. This memory is not writable. You need to copy the string to a writable location, either on the stack (as you did in your second example), or on the heap (by allocating memory usingnew
).
Who is 'General Failure'? And why is he reading my harddisk?!?