C语言:将两个字符串连接起来。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言:将两个字符串连接起来。相关的知识,希望对你有一定的参考价值。

【程序】
#include <stdio.h>
int main()

char s1[80],s2[40];
int i=0,j=0;
printf("\nInput the first string:");
scanf("%s",s1);
printf("\nInput the second string:");
scanf("%s",s2);
while (s1[i] !='\0')
______1______;
while (s2[j] !='\0')
______2______; /* 拼接字符到s1 */
s1[i] ='\0';
printf("\nNew string: %s",s1);


请补充

#include <stdio.h>
int main()

char s1[80],s2[40];
int i=0,j=0;
printf("\nInput the first string:");
scanf("%s",s1);
printf("\nInput the second string:");
scanf("%s",s2);
while (s1[i] !='\0')
i++;
while (s2[j] !='\0')
s1[i++]=s2[j++]; /* 拼接字符到s1 */
s1[i] ='\0';
printf("\nNew string: %s",s1);
参考技术A void main()

void con(char sting1[],char sting2[],char sting3[]);
char s1[20],s2[20],s3[40];

printf("Input sting1: ");
scanf("%s",s1);
printf("Input sting2: ");
scanf("%s",s2);
con(s1,s2,s3);
printf("%s\n",s3);

void con(char sting1[],char sting2[],char sting3[])

int i,j;
for(i=0;sting1[i]!='\0';i++)//////////////////////////多个分号
sting3[i]=sting1[i];

for(j=0;sting2[j]!='\0';j++)//////////////////////////多个分号
sting3[i+j]=sting2[j];
sting3[i+j]='\0';

另外,站长团上有产品团购,便宜有保证
参考技术B 这些是宏的功能。#是将一个参数转换为字符串。##可以连接字符串 比如这样:#include
<stdio.h>
#define
STR(a,b)
a##bint
main()
printf("%s
",STR("123","456"));
return
0;
参考技术C i++; 1
s1[i] = s2[i];

C语言编写一个程序,将两个字符串连接起来,不要使用strcat函数

#include "stdio.h"
void main()

    char a[50],b[50],c[50];
    int i=0,j=0,k=0;
printf("输入第一个字符串");
gets(a);
printf("输入第二个字符串");
gets(b);
    printf("a=%s\\n",a);
    printf("a=%s\\n",b);
    while(a[i])c[k++]=a[i++];
    while(b[j])c[k++]=b[j++];
    c[k]=b[j];
    printf("c=%s",c);

已经运行过,有什么问题请留言!

参考技术A //函数是以前写的,测试通过,如果有疑问,欢迎交流
//依次输入两个字符串就行
#include<stdio.h>
#define N 100
void cur_stract(char *src, char* tar)
int cur_count = 0;
while(src[cur_count]!='\\0')
cur_count++;

int tar_cur_count = 0;
while(tar[tar_cur_count]!='\\0')
src[cur_count] = tar[tar_cur_count];
tar_cur_count++;
cur_count++;

src[cur_count] = '\\0';

int main()
char a[N], b[N];
gets(a);
gets(b);
cur_stract(a,b);
puts(a);
return 0;

参考技术B 函数头我就不和你写了!
int a[20],b[20],i=0,j=0;
while(a[i]!='\0')

i++;

while(b[i]!='\0')

a[i++]=b[i++];

a[i]='\0';
printf("%s",a);

就可以了!!

以上是关于C语言:将两个字符串连接起来。的主要内容,如果未能解决你的问题,请参考以下文章

用c语言如何连接两个中文字符串?

C语言编写一个程序,将两个字符串连接起来,不要使用strcat函数

C语言编程:5、编一个程序,将两个字符串连接起来,不要用strcat函数.

编写一个程序,将两个字符串连接起来,并输出(不要使用strcat函数)。用C语言求解详细过程。

如何在MySQL中连接两个字符串

Sybase 字符串连接