编程将两个字符串连接起来 输入两行,每行一个字符串(只包含小写字母长度不超过100)输出一行一个字符串

作者&投稿:符南 (若有异议请与网页底部的电邮联系)
C语言:从键盘输入一个不超过100个字符的字符串,其中字符串只包括字母、数字、空格三种字符。~

1、首先需要打开编程软件。

2、输入以下程序:#include int main(){ char str[40]; scanf("%s",&str); printf("%s",str); return 0;}。

3、然后按F5运行程序。

4、然后输入想要输入的字符串。

5、按回车键,就会弹出你输入的字符串。

6、注意字符串的大小,改变中括号中的数字改变输入字符串的大小。

#include
#include
int main()
{char s[200],s1[200];
int n,max=0;
while(1)
{gets(s);
if(strcmp(s,"***end***")==0)
break;
n=strlen(s);
if(n>max)
{max=n;strcpy(s1,s);
}
}
printf("%d
%s
",max,s1);
return 0;
}

你好 :
这道题搜先思路是找三个指针,其中一个指针用来存放连接后的串,宁外两个指针用来存放输入的目标串:
代码如下:
#include <stdio.h>#include <string.h>#include <malloc.h> int main(){ char *str1 = (char*)malloc(sizeof(char) *100); char *str2 = (char*)malloc(sizeof(char) *100); char *str3 = (char*)malloc(sizeof(char) *200); gets(str1); gets(str2); strcpy(str3, str1); strcat(str3, str2); puts(str3); free(str1); free(str2); free(str3); return 0;
}
你要多看看串的连接函数,就懂了这个道理了。

#include <stdio.h>
#include <string.h>
#include <malloc.h>

int main()
{
  char *str1 = (char*)malloc(sizeof(char) *100);
  char *str2 = (char*)malloc(sizeof(char) *100);
  char *str3 = (char*)malloc(sizeof(char) *200);

  gets(str1);
  gets(str2);

  strcpy(str3, str1);
  strcat(str3, str2);

  puts(str3);

  free(str1);
  free(str2);
  free(str3);

  return 0;
}



c语言编程 要用指针把两个字符串连接起来, 我这么编的不知道哪错了...
语法有错误,可以按照如下方法实现用指针把两个字符串连接起来:1、第一步,创建一个新项目和.c文件,见下图,转到下面的步骤。2、第二步,执行完上面的操作之后,定义变量类型,见下图的代码,转到下面的步骤。3、第三步,执行完上面的操作之后,调用cpy函数,见下图的代码,转到下面的步骤。4、第四...

C语言编程题目?
下面是一个可以利用指针将两个字符串连接起来的 C 语言程序。该程序定义了一个子函数 `StrCat`,用于将两个字符串连接起来,并返回连接后的结果。主函数中,我们先从标准输入读入两个字符串,然后根据它们的长度调用 `StrCat` 函数,将它们连接起来并输出结果。```c include <stdio.h> include <...

C++编写一个程序,将从键盘输入的两个字符串连接起来,并统计连接好的字符...
输入两个字符串,第一个按下标往后找结束符,找到后,从这里开始将第二个字符串内容copy过来,不知道长度不要紧,也按下标一字节一字节copy,遇到'\\0'停止,新的字符串结尾也要加结束符,这样,就是自己实现的简单的strcat函数,这里不仅能得到连接后的字符串,还能知道传入的两个字符串的长度。

不用指针来编写程序strcat,将两个字符串连接起来
详细代码就不写了,简单说一下想法,先把相加的两个字符串转化成数字表示,新串=前串*10**(lg(后串)+1)+后串,再转化回来,不过这么做有点麻烦。还是用指针简单

编写一程序,将两个字符串连接起来,不使用strcat函数
char *MyStrcat(char *str1, char *str2){ char *pt=str1;if((str1==NULL)||(str2==NULL))return NULL;while(*str1!='\\0') str1++;while(*str2!='\\0') *str1++ = *str2++;str1 = '\\0';return pt;}

c++中,编写一个程序,将两个字符串了连接起来,结果取代第一个字符串...
std::string a= "0123";std::string b = "4567";a = a + b;

编写一个C++程序,将两个字符串连接起来,不用strcat函数
完整源代码 include<stdio.h> void main(){char s1[80],s2[40];int i=0,j=0;printf("\\ninput string1:");scanf("%s",s1);printf("input string2:");scanf("%s",s2);while(s1[i]!='\\0')i++;while(s2[j]!='\\0')s1[i++]=s2[j++];s1[i]='\\0';printf("The new ...

.编写一个程序,将从键盘输入的两个字符串,将它们连接起来,要求利用指针...
scanf("%c",&str2[i]);i++;} while (str2[i-1]!='*');\/*---*\/ \/*---连接字符串---*\/ p1=str1;p2=str2;while (*p1) p1++;while (*p2){ p1=*p2;p1++;p2++;} p1='\\0';printf("\/n The New String is:%s\\n",p1);\/*---...

[C语言] 不用strcat()函数,将两个字符串连接起来,试完善一下程序!_百 ...
include<stdio.h> int main(){ char s1[80],s2[40];int i,j;printf("Enter s1:");scanf("%s",s1);printf("Enter s2:");scanf("%s",s2);for(i=0;s1[i];i++);for(j=0;s1[i++]=s2[j++];);printf("\\nResult is:%s",s1);getch();return 0;} ...

C语言编程:输入2个字符串,将其连接后输出.
思路:两个字符串的拼接可以使用strcat函数。strcat函数原型: char *strcat(char *s1,char *s2);需要引入头文件:#include <string.h> 功能:把s2所指字符串添加到s1结尾处并添加'\\0'。注意:s1必须有足够的空间来容纳s1和s2的字符串。参考代码:include "stdio.h" #include "string.h" int ...

阿尔山市17845369708: 编程将两个字符串连接起来 输入两行,每行一个字符串(只包含小写字母长度不超过100)输出一行一个字符串 -
蔡态高特: 你好 :这道题搜先思路是找三个指针,其中一个指针用来存放连接后的串,宁外两个指针用来存放输入的目标串:代码如下:#include <stdio.h>#include <string.h>#include <malloc.h> int main(){ char *str1 = (char*)malloc(sizeof(char) *100); char *...

阿尔山市17845369708: 用C语言怎么将两个字符串连接起来? -
蔡态高特: 这些是宏的功能. #是将一个参数转换为字符串.##可以连接字符串比如这样: #include <stdio.h> #define STR(a,b) a##b int main() { printf("%s\n",STR("123","456")); return 0; }

阿尔山市17845369708: 编写程序“编写函数实现将两个字符串的连接”. -
蔡态高特: /*运行结制果为: 请输入string1: chinsung 请输入string2: lee string1, string2两字2113符串连5261接后4102的结果为:1653 chinsunglee. */ #include #include char concatenate(char string1[], char string2[]) { int i,j; i=strlen(string1); for(j=0;j

阿尔山市17845369708: C语言编程:编一程序,将两个字符串联接起来,不要用Strcat函数. -
蔡态高特: 思路:输入两个字符串a和b,首先找到第一个字符串a的结束位置,接着把b的所有元素放到a的末尾,最后加上结束标志. 参考代码: #include<stdio.h> void mystrcat(char a[],char b[]){int i=0,j=0;while(a[i++]!='\0');//找到a的结束位置i--;...

阿尔山市17845369708: 在C语言编程中,如何利用调用函数来把两个字符串连接起来? -
蔡态高特: strcat(a,b)把字符串b连到字符串a后面 举例; strcat("wo","niu");//输出woniu

阿尔山市17845369708: C语言编程:5、编一个程序,将两个字符串连接起来,不要用strcat函数. -
蔡态高特: 思路:字符串连接先需要找到第一字符串的结束位置,接着把第二字符串元素放到第一字符串后面,最后加上结束标志即可.参考代码:拼接123和456#include<stdio.h> void mystrcat(char a[],char b[]){//字符串连接函数int i=0,j=0; while(a[i++]!='\0...

阿尔山市17845369708: C语言:将两个字符串连接起来. -
蔡态高特: 原发布者:hxk古月#define_CRT_SECURE_NO_WARNINGS#include#include#includevoidmystrcat(char*p,char*q){char*pp=p;while(*pp!='\0'){pp++;}*pp='';while(*q!='\0'){*(++pp)=*(q++);}*(++pp)='\0';}voidmain(){charstr[30]="tracert";charweb[50];...

阿尔山市17845369708: 用c语言编写一个将两个字符串连接起来函数两个字符串由主函数输入, 连接后的字符串也由主函数输出. -
蔡态高特: #include<stdio.h> 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(...

阿尔山市17845369708: 用strcate写程序将两个字符串连接起来 -
蔡态高特: #include void strcate(char *s1, char *s2, char *s3){ strcpy(s3,strcat(s1,s2)); //调用 strcat } int main(){ char s1[20]="abc 123",s2[20]=" XYZ 987",s3[80]; strcate(s1,s2,s3); printf("%s",s3); return 0; }

阿尔山市17845369708: 如何用C语言数组编写程序,将两个字符串连接起来 -
蔡态高特: #include 方法一:如mtcat所说,直接用strcat函数 方法二:编程实现strcat的功能 void main() { char s1[80],s2[80]; int i=0,j=0; puts("input two strings:"); gets(s1); gets(s2); while(s1[i]!='\0') i++; while((s1[i++]=s2[j++])!='\0'); printf("result:%s\n",s1); }

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网