302班

          java突擊隊(duì)
          posts - 151, comments - 74, trackbacks - 0, articles - 14
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          字符數(shù)組的定義:
            char word[]="Hello!";
          或者:
            char word[]={"Hello!"};
          或者:
            char word[7]={'H','e','l','l','o','!','\0'};
          注意:C語(yǔ)言中所有的常數(shù)字符串都是以空字符結(jié)尾的,這樣很多常用的函數(shù)才能知道字符串的結(jié)尾在哪里。
          #include <stdio.h>

          int main(void)
          {
            void concat(char result[],const char str1[],const char str2[]);
            const char s1[]={"Test "};
            const char s2[]={"works!"};
            char s3[20];

            concat(s3,s1,s2);

            printf("%s\n",s3);//盡管s3中有20個(gè)元素,但使用了%s格式描述符調(diào)用printf函數(shù)顯示。
                                     //%s是用來(lái)顯示空字符結(jié)的字符串;

            return 0;

          }

          void concat(char result[],const char str1[],const char str2[])
          {
             int i,j;

             for(i=0;str1[i]!='\0';i++)
             {
               result[i]=str1[i];
             }

             for(j=0;str2[j]!='\0';j++)
             {
               result[i+j]=str2[j];
             }
             result[i+j]='\0';
          }
          運(yùn)行結(jié)果:

          主站蜘蛛池模板: 临海市| 惠安县| 安国市| 治多县| 利辛县| 修水县| 郁南县| 卢氏县| 石狮市| 嘉义县| 北京市| 如东县| 辽阳市| 三穗县| 南城县| 花莲县| 平度市| 拜城县| 米易县| 通化市| 台前县| 伊金霍洛旗| 隆化县| 万载县| 长武县| 辽宁省| 福建省| 黄梅县| 区。| 石家庄市| 穆棱市| 石台县| 饶河县| 阿城市| 和顺县| 井陉县| 白银市| 金沙县| 林州市| 廊坊市| 象州县|