strcat
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *firstName = "Hello";
char * lastName = "World";
char *name = (char *) malloc(strlen(firstName)+strlen(lastName));
strcpy(name,firstName);
strcat(name,lastName);
printf("s%\n",name);
return 0;
}
sprintf
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char *firstName = "Hello";
char *lastName = "World";
char *name = (char *) malloc(strlen(firstName) + strlen(lastName));
sprintf(name, "%s%s", firstName, lastName);
printf("%s\n", name);
return 0;
}
|