Jump to content

String append: Difference between revisions

no edit summary
No edit summary
Line 60:
int main()
{
char str[10024]="Good Morning";
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*/
x=strlen(str); {
/* 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>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.