pointer operation


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: pointer operation

  1. #1
    Join Date
    May 2005
    Posts
    58

    Question pointer operation

    i have two pointers

    wchat_t *str and wchar_t * etr

    srt is pointing to wchar_t type data like 11.22.11.22
    and etr is also pointing to simlilar data. 12.32.14.32

    Now i want to have a pointer which points to the (combined) data of both the pointers like this
    wchar_t *stretr it should point to the 11.22.11.22 12.32.14.32

    please tell me how to get this pointer?what operations are required on str and etr?

    somthing like this is possible?
    wchar_t join = str +' '+etr;
    then make stretr points to join?

  2. #2
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    Hi,

    wchar_t join = str +' '+etr;
    what you are trying to do here is adding memory addresses.
    str points to the memory address where the data 11.22.11.22 lies.
    Similarly etr points to a memory address. What you try to do in the statement
    wchar_t* join = str +' '+etr;
    is to assign a memory address to 'join' which is the sum of the addresses of str and etr plus the ASCII value of the character space ' '. That's not what you want.
    Try functions like wstrcat or wsprintf to do what you want or better yet: try to use
    the STL. There is a class "string", that probably does what you want.
    But I believe the string - class is based char rather than wchar_t, if this is a concern...

    #include <string>
    using namespace std;
    int main()
    {
    string str1 = "11.22.33.44";
    string str2 = "55.66.77.88";
    string str3 = str1 + string(" ") + str2; // str3 == "11.22.33.44 55.66.77.88"

    return 0;
    }


    Regards,

    Dieter

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    Quote Originally Posted by swapnil_paranja
    somthing like this is possible?
    wchar_t join = str +' '+etr;
    then make stretr points to join?
    It's possible but not with bare pointers. Use std::wstring objects for this purpose:

    Code:
    #include <string> //mind the header's name: not string.h!
    
    using std::wstring;
    
    wstring joined= wstring(str)+wstring(etr);
    If you need to extract the address of the joined string, use

    Code:
    const wchar_t *ptr = joined.data();
    Danny Kalev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center