Click here to Skip to main content
15,909,656 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,

Can anybody please help me to create a string from 2 char* variables.

Thanks & Regards,
Lokesh
Posted
Comments
Resmi Anna 15-Jun-11 4:55am    
What you actually need? Its not clear. You need to create a string by concatenating two char* variable content?
lokeshughade 15-Jun-11 5:01am    
yes...
i have a function that gives me 2 char* variables
i want to create a string from those 2 variables
Resmi Anna 15-Jun-11 5:10am    
strcat()...this is very basic..google first,if no use then only "post a qstn"..to save ur time...

1 solution

Allocate a area of memory big enough for both the two character arrays, and use strcpy[^] - don't forget to remove any trailing null from the first, and make sure there is a null after / at the end of the second.
 
Share this answer
 
Comments
[no name] 15-Jun-11 5:19am    
And why not simply use strcat()?

Cats are always a good thing :)
[no name] 15-Jun-11 17:52pm    
And C strings do not have a trailing null. It's a char with the value zero, That may sound like nitpicking, but long ago I learned that it is not safe to assume that null, NULL or whatever really equals zero.
OriginalGriff 16-Jun-11 3:14am    
Habit: I'm used to a char '\x00' being an ASCII null... :laugh:
[no name] 16-Jun-11 3:20am    
Well, the new C++ standard will have you change your habits. Finally the null value is defined as part of the language.
OriginalGriff 16-Jun-11 3:27am    
Is there a NULLorette patch available to wean me off gently? I've been using ASCII for a very long time...:laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900