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

  #2  
Jul 27th, 2005
OK, I've tried to simplify the example. Same problem happens here:
#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[0]<<endl;
 
}

Result:
./Test
tester is null
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:27 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