用于在C中连接两个字符串的程序(Program to concatenate two strings in C)

优质
小牛编辑
130浏览
2023-12-01

实现 (Implementation)

现在,我们将看到该计划的实际执行情况 -

#include <stdio.h>
#include <string.h>
int main() {
   char s1[10] = "Taj";
   char s2[] = "Mahal";
   int i, j, n1, n2;
   n1 = strlen(s1);
   n2 = strlen(s2);
   j = 0;
   for(i = n1; i< n1+n2; i++ ) {
      s1[i] = s2[j];
      j++;
   }
   s1[i] = '\0';
   printf("%s", s1);
   return 0;
}

输出 (Output)

该计划的输出应为 -

TajMahal