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

C\u8bed\u8a00\uff1a\u4ece\u952e\u76d8\u8f93\u5165\u4e00\u4e2a\u4e0d\u8d85\u8fc7100\u4e2a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5b57\u7b26\u4e32\u53ea\u5305\u62ec\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u7a7a\u683c\u4e09\u79cd\u5b57\u7b26\u3002

1\u3001\u9996\u5148\u9700\u8981\u6253\u5f00\u7f16\u7a0b\u8f6f\u4ef6\u3002

2\u3001\u8f93\u5165\u4ee5\u4e0b\u7a0b\u5e8f\uff1a#include int main(){ char str[40]; scanf("%s",&str); printf("%s",str); return 0;}\u3002

3\u3001\u7136\u540e\u6309F5\u8fd0\u884c\u7a0b\u5e8f\u3002

4\u3001\u7136\u540e\u8f93\u5165\u60f3\u8981\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u3002

5\u3001\u6309\u56de\u8f66\u952e\uff0c\u5c31\u4f1a\u5f39\u51fa\u4f60\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u3002

6\u3001\u6ce8\u610f\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\uff0c\u6539\u53d8\u4e2d\u62ec\u53f7\u4e2d\u7684\u6570\u5b57\u6539\u53d8\u8f93\u5165\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u3002

#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\n%s\n",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++如何连接两个字符串 ... c#两个字符串相连接 ... c 怎么输入一个字符串 ... c语言合并两个字符串 ... 编程交换两个字符串 ... c #根据符号分割字符串 ... 编程实现两个字符串的连接 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网