如何用C语言数组编写程序,将两个字符串连接起来 C语言中怎么样将两个字符串连接起来

\u7528c\u8bed\u8a00\u7f16\u5199\u7a0b\u5e8f,\u5c06\u4e24\u4e2a\u5b57\u7b26\u4e32\u8fde\u63a5\u8d77\u6765,\u4e0d\u8981\u7528strcat\u51fd\u6570

#include #include void strc(char c1[],char c2[]);void main(){char s1[30]="abc";char s2[30]="def";strc(s1,s2); //\u8bf7\u5728\u540e\u9762\u8865\u5145strc\u51fd\u6570\u7684\u529f\u80fd\uff0c\u5b8c\u6210\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u8fde\u63a5puts(s1);}void strc(char c1[],char c2[]){ //\u8bf7\u586b\u7a7a\uff0c\u5b8c\u6210\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u8fde\u63a5 int i,j; for(i = 0; c1[i]; i ++); for(j = 0; c2[j]; j ++) c1[i+j] = c2[j]; c1[i+j] = 0;}

1)\u7b80\u5355\u6765\uff0c\u76f4\u63a5\u7528 strcat \u51fd\u6570\uff0c\u9700\u8981\u5305\u542b\u5934\u6587\u4ef6 string.h2)\u81ea\u5df1\u5b9e\u73b0\u7684\u8bdd\u4e5f\u4e0d\u9ebb\u70e6\uff0c\u4f46\u662f\u8981\u8003\u8651\u4e00\u4e9b\u7ec6\u8282\uff1a\u5047\u8bbe\u4e24\u4e2a\u5b57\u7b26\u4e32\u6307\u9488\u4e3a str1\uff0cstr2 \uff0c\u73b0\u5728\u8981\u8bb2 str1 \u548c str2 \u8fde\u63a5\u6210\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u3002a.\u8003\u8651\u6307\u9488 str1,str2 \u662f\u5426\u975e\u7a7ab.\u5982\u679c\u5c06str2\u7684\u5185\u5bb9\u76f4\u63a5\u8fde\u63a5\u5230str1\u7684\u672b\u5c3e\uff0c\u8981\u8003\u8651str1\u662f\u5426\u6709\u8db3\u591f\u7684\u5269\u4f59\u7a7a\u95f4\u6765\u653e\u7f6e\u8fde\u63a5\u4e0a\u7684str2\u7684\u5185\u5bb9\u3002\u5982\u679c\u7528\u4e00\u4e2a\u65b0\u7684\u5185\u5b58\u7a7a\u95f4\u6765\u4fdd\u5b58str1\u548cstr2\u7684\u8fde\u63a5\u7ed3\u679c\uff0c\u9700\u8981\u52a8\u6001\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u3002

void main()
{
    char A[4]={'a','b','c','\0'};//字符串A
    char B[4]={'d','e','f','\0'};//字符串B
    char C[7];////字符串A和字符串B连接起来后的字符串
    int i;
    for(i=0;i<3;i++)
        C[i]=A[i];
    for(i=0;i<3;i++)
        C[i+3]=B[i];
    C[6]='\0';
    for(i=0;i<7;i++)
        printf(C[i]);
}


  • 濡備綍鐢–璇█缂栧啓涓涓惊鐜绋嬪簭?
    绛旓細1銆侀鍏堬紝瀹氫箟涓や釜鏁村瀷鍙橀噺锛屾帶鍒朵簩缁鏁扮粍鐨勮緭鍑恒2銆佹帴鐫锛岀粰浜岀淮鏁扮粍n[3][4]鍒濆鍖栦笉鍚岀殑鏁板笺3銆佺敤浜岄噸寰幆锛岃緭鍑烘暟缁勪腑鐨勫悇涓暟鍊笺4銆佷簩缁存暟缁勫彲浠ョ敤澶ф嫭鍙锋嫭璧锋潵鐨勬暟瀛楃洿鎺ヨ祴鍊硷紝鍐呭眰澶ф嫭鍙蜂腑姣忓琛ㄧず涓琛岋紝姣忓鍐呭眰澶ф嫭鍙蜂腑鐨勫艰〃绀轰竴琛屼腑鐨勫悇鏁板笺5銆佽繍琛绋嬪簭锛鍙互鐪嬪埌浜岀淮鏁扮粍涓殑鍊硷紝...
  • ...鏁扮粍鏈変簲涓暣鏁,灏涓よ呭悎骞跺埌鏁扮粍c鍚庤緭鍑恒c璇█瀹炵幇?
    绛旓細include<stdio.h> int main(){ int i,j,a[5],b[5],c[10];for(i=0; i<5; i++)scanf("%d",&a[i]);for(i=0; i<5; i++)scanf("%d",&b[i]);for(i=0; i<5; i++)c[i]=a[i];for(j=0; j<5; j++)c[i++]=b[j];for(i=0; i<10; i++)printf("%d ...
  • C璇█涓濡備綍灏嗕袱涓簩缁鏁扮粍鍚堝苟涓轰竴涓簩缁存暟缁勪腑銆傚笇鏈涢珮鎵嬪彲浠ュ府鎴戞妸...
    绛旓細鎬庝箞鍚堝苟锛屾槸閫氳繃璁$畻鍔犲噺娉曡繕鏄帓搴忔彃鍏 銆備笅闈㈡槸灏哸杩炴帴b褰㈡垚c include <stdio.h> include <stdlib.h> define M 3 define N 3 //鍒涘缓鐭╅樀 int ** Create(int m,int n){ int i;int **x;x=(int**)malloc(sizeof(int*) * m);if(!x){ printf("鍒嗛厤鍐呭瓨鍑洪敊\n");exit(1);} fo...
  • 缂栧啓涓涓绋嬪簭,灏嗕袱涓瓧绗︿覆杩炴帴璧锋潵,骞惰緭鍑(涓嶈浣跨敤strcat鍑芥暟)銆鐢–...
    绛旓細include<stdio.h> void main(){ char s1[80],s2[40];int i=0,j=0;printf("\ninput stringl:");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 string is:%s...
  • 鎬庝箞鐢╟璇█灏嗕袱涓鏁扮粍骞惰捣鏉?
    绛旓細鐪嬩唬鐮锛屽啓浜嗗嚑绉鏁扮粍鐨勫悎骞讹細include<stdio.h>#include<stdlib.h>#include<string.h>void character(){char c1[]={'H','e','l','l','o'};char c2[]={' ','w','o','r','l','d','!'};int k=0;char new_c[100];for(int i=0;i<sizeof(c1);i++)//娉ㄦ剰鏄痵izeof锛...
  • 鐢–璇█缂栫▼:杈撳叆涓や釜鏁村瀷鏁扮粍x[4],y[4]鍚勫厓绱犵殑鍊,杈撳嚭涓や釜鏁扮粍瀵瑰簲鍏...
    绛旓細} printf("enter Y\n");/*寰幆杈撳叆鏁扮粍y*/ for(i=0;i<4;i++){ scanf("%d",y+i);} for(i=0;i<4;i++)/*寰幆姹傛暟缁勫拰锛屽苟涓旇緭鍑*/ { sum[i]=x[i]+y[i];printf("%d\t",sum[i]);} getch();} 缁撴灉 enter X 1 2 3 4 enter Y 1 2 3 4 2 4 6 8 ...
  • c璇█:杈撳叆涓涓绋嬪簭,杈撳叆涓や釜鏁村瀷鏁扮粍x銆4銆戙亂銆4銆戝悇鍏冪礌鍊,杈撳嚭涓や釜...
    绛旓細include<stdio.h> int main(){ int x[5],y[5],s[5];int i;for(i=0;i<5;i++){ scanf("%d",&x[i]);scanf("%d",&y[i]);s[i] = x[i]+y[i];} for(i=0;i<4;i++){ printf("%d ",s[i]);} printf("%d\n",s[4]);return 0;} ...
  • 鎬ュ晩,鐢–璇█姹備袱涓鏁扮粍骞堕泦骞朵笖鎸夐『搴忚緭鍑,杩樺緱杈撳嚭骞堕泦涓厓绱犵殑涓暟...
    绛旓細绾C鐨勪唬鐮佸涓嬨 鍩烘湰鏄厛瀵逛袱涓鏁扮粍鎺掑簭锛 鐒跺悗鍐嶆眰骞堕泦銆備唬鐮佸涓嬶細include <stdio.h> include <stdlib.h> int compare (const void * a, const void * b);void FindUnion(const int *pa1, const int *pa2, const size_t m, const size_t n);int main(int argc, char *argv[]){...
  • 鐢╟璇█瀹炵幇杈撳叆涓や釜浜岀淮鏁扮粍,骞跺皢瀵瑰簲鍏冪礌鐩稿姞骞惰緭鍑,涓嶈淇濆瓨鍒扮...
    绛旓細include <stdio.h>#define M 3#define N 4int main(){int i,j,a[M][N],b[M][N];printf("杈撳叆绗竴涓簩缁鏁扮粍:\n");for(i=0;i<M;i++)for(j=0;j<N;j++)scanf("%d",&a[i][j]);printf("杈撳叆绗簩涓簩缁存暟缁:\n");for(i=0;i<M;i++)for(j=0;j<N;j++)scanf("...
  • c璇█! 缂栦竴绋嬪簭,灏嗕袱涓瓧绗︿覆杩炴帴璧锋潵,涓嶈鐢╯trcat鍑芥暟.
    绛旓細鎬濊矾锛氬瓧绗︿覆杩炴帴鍏堥渶瑕佹壘鍒扮涓瀛楃涓茬殑缁撴潫浣嶇疆锛屾帴鐫鎶婄浜屽瓧绗︿覆鍏冪礌鏀惧埌绗竴瀛楃涓插悗闈紝鏈鍚庡姞涓婄粨鏉熸爣蹇楀嵆鍙傚弬鑰冧唬鐮侊細鎷兼帴123鍜456 include<stdio.h>void mystrcat(char a[],char b[]){//瀛楃涓茶繛鎺ュ嚱鏁 int i=0,j=0;while(a[i++]!='\0');//鎵惧埌a鐨勭粨鏉熶綅缃 i--;while(b[j...
  • 扩展阅读:学编程一年大概多少钱 ... 关于数组的c语言程序 ... 初学编程必背50个 ... c++入门程序代码 ... 小学生c++趣味编程视频 ... 编程必背100个代码 ... 编程c++语言入门自学 ... 10个常用的编程语言 ... 如何自己编程做游戏 ...

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