C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-30-2009, 10:12 PM   #1
Registered User
 
Join Date: Sep 2009
Location: california
Posts: 7
Need some more help this time with Pointer help

k so im working on putting the value (what is being pointed to) from a pointer and adding
it to the end of a string.

Code:
STRING& STRING::operator+=(char* c)
{
    char* Temp = new char [Len+1];
    for (unsigned I= 0; I <Len; I++){
        Temp [i]= STR[i];
    }
    Len+=1;
    
    Temp[Len]=char(c); // this is where im trying to add the pointer
    
    delete [] STR;
    STR = Temp;
    return *this;
}
akairyuu is offline   Reply With Quote
Old 09-30-2009, 11:13 PM   #2
Ex scientia vera
 
Join Date: Sep 2007
Posts: 426
If this is the overload that only adds a single character, then you need to change your code:

Code:
STRING& STRING::operator+=(char* c) // Remove part in red
{
    char* Temp = new char [Len+1];
    for (unsigned I= 0; I <Len; I++){
        Temp [i]= STR[i];
    }
    Len+=1;
    
    Temp[Len]=char(c); // this is where im trying to add the pointer
    
    delete [] STR;
    STR = Temp;
    return *this;
}
__________________
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."
IceDane is offline   Reply With Quote
Reply

Tags
pointers

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help in time zone Gong C++ Programming 2 01-03-2007 04:44 AM
pointers InvariantLoop C Programming 13 02-04-2005 09:32 AM
towers of hanoi problem aik_21 C Programming 1 10-02-2004 01:34 PM
Killing someones grandparents nickname_changed A Brief History of Cprogramming.com 37 09-07-2003 07:56 AM
Contest Results - May 27, 2002 ygfperson A Brief History of Cprogramming.com 18 06-18-2002 01:27 PM


All times are GMT -6. The time now is 08:27 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22