Anonymous user
String append: Difference between revisions
no edit summary
No edit summary |
|||
Line 60:
int main()
{
char str[
char *cstr=" to all";
char *cstr2=" !!!";
int x=0;
//failure when space allocated to str is insufficient.
/* 1st method*/▼
strcat(str,cstr);▼
if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
/*2nd method*/▼
▲ /* 1st method*/
sprintf(&str[x],"%s",cstr2);▼
▲ strcat(str,cstr);
▲ /*2nd method*/
printf("%s\n",str);▼
x=strlen(str);
▲ sprintf(&str[x],"%s",cstr2);
▲ printf("%s\n",str);
}
return 0;
}</lang>
|