Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Chaging Characters;

Chaging Characters;

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bo Hunter
    wrote on last edited by
    #1

    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

    P J 2 Replies Last reply
    0
    • B 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

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      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)

      B 1 Reply Last reply
      0
      • P Prakash Nadar

        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)

        B Offline
        B Offline
        Bo Hunter
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • B 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

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          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 using new).


          Who is 'General Failure'? And why is he reading my harddisk?!?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups