Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum two string variables 2

Status
Not open for further replies.

thinICE80

Programmer
Sep 14, 2005
6
IT
Hi,
anyone knows how to sum two string variables, I've tried with strcat but this function accept as the second parameter only a constant string. I want to do something like this:

char var1[10], var2[10], var3[20];

var1 = strcpy(var1,"hewhwho");
var2 = strcpy(var2,"fhhgoehg");
var3 = strcat(var1,var2);

Thanks for your help.
 
I've tried with strcat but this function accept as the second parameter only a constant string
All right then non-constant arg is accepted too, that's all.
Let's remember:
strcpy(s1,s2) is the same as s1 = s2, s1 != s2.
strcat(s1,s2) is the same as s1 = s1 + s2, s1 != s2.
These functions returns 1st arg (i.e. a pointer to the 1st modified array of char) and both are very dangerous (char array overwriting possible).
May be it helps in your homework? Read this forum rules... Good luck!
 
non-const variables can automatically be promoted to const, but const variables cannot be demoted to non-const without an explicit cast.
Code:
char* var1 = "non-const data";
const char* var2 = var1;  /* char* becomes const char* -- OK. */
char* var3 = var2;  /* Error!  const char* cannot become char*. */
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top