Menggabungkan dua kalimat menjadi satu langage c
#include <stdio.h>
#include <string.h>
void strcp(char *sender, int snder_size, char *reciever, int start_index)
{
for (int x = 0; x < snder_size; x++)
{
reciever[start_index + x] = sender[x];
}
}
char *addTwoStrings(char *str1, int str1_size, char *str2, int str2_size, char *reciever)
{
strcp(str1, str1_size, reciever, 0); // 0 -> str1_size-1
reciever[str1_size] = ' ';
strcp(str2, str2_size, reciever, str1_size + 1); // str1_size+1 -> (str1_size + str2_size)-1
return reciever;
}
int main()
{
int length1, length2 , length3;
char str1[1000];
char str2[1000];
char str3[2001];
printf("Enter the first str : ");
scanf("%s", str1);
length1=strlen(str1);
printf("Enter the second str : ");
scanf("%s", str2);
length2=strlen(str2);
addTwoStrings(str1, length1, str2, length2, str3);
printf("the total string is :%s", str3);
return 0;
}
abd elmoumaine nessah