RSS Forums RSS
Please support our C++ advertiser: Programming Forums

Passing char * to function and populating inside

Join Date: Feb 2005
Posts: 464
Reputation: winbatch is on a distinguished road 
Rep Power: 4
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Passing char * to function and populating inside

  #3  
Jul 27th, 2005
I was able to get it to work, however is this the right way?
#include <iostream.h>
void test( char ** fillMe)
{
		*fillMe = new char[10];
		memset( *fillMe, '\0', 10 );
		strcpy( *fillMe, "TESTING" );
}
int main()
{
		char * tester=NULL;
		test( &tester );
		if ( tester == NULL )
		{
				cout<< "tester is null"<<endl;
		}
		else
				cout<<tester<<endl;
		if ( tester !=NULL )
				delete [] tester;
 
 
}
Result:
./Test
TESTING
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:30 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC