来自「我的串的连接算法实现」· 代码 · 共 25 行

TXT
25
字号
#include<stdio.h>
#include<string.h>
# define MAX 128 
int slength (char ch[])
{
	int i=0; 
    while (ch[i]!='\0')i++;
    return i; 
} 

int main() 
{
   int i,j; 
   char ch1[MAX],ch2[MAX],des[MAX]; 
   printf("input the first string:");
   scanf("%s",ch1); 
   printf("input the second string:");
   scanf("%s",ch2); 
   if (slength(ch1) + slength(ch2)> MAX)return 1; /*目标串的存贮区不够大*/ 
   for(j=0; j<slength(ch1); j++)des[j]= ch1[j]; 
   for(i=0; i<slength(ch2); j++, i++)des[j]= ch2[i]; 
   des[j]='\0'; /*添加串的结束符号*/ 
   printf("%s\n",des); 
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?