<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # C `strncat()`函數 > 原文: [https://beginnersbook.com/2017/11/c-strncat-function/](https://beginnersbook.com/2017/11/c-strncat-function/) 在上一個教程中,我們討論了 [`strcat()`函數](https://beginnersbook.com/2017/11/c-strcat-function-with-example/),它用于將一個字符串連接到另一個字符串。在本指南中,我們將看到類似的**`strncat()`函數**,它與 `strcat()`相同,只是 `strncat()`只將指定數量的字符附加到目標字符串。 ## C `strncat()`函數聲明 ```c char *strncat(char *str1, const char *str2, size_t n) ``` `str1` - 目標字符串。 `str2` - 附加在目標字符串`str1`末尾的源字符串。 `n` - 需要追加的源字符串`str2`的字符數。例如,如果這是 5,則只有源字符串`str2`的前 5 個字符將附加在目標字符串`str1`的末尾。 **返回值:**該函數返回指向目標字符串`str1`的指針。 ## 示例:C 中的`strncat()`函數 ```c #include <stdio.h> #include <string.h> int main () { char str1[50], str2[50]; //destination string strcpy(str1, "This is my initial string"); //source string strcpy(str2, ", add this"); //displaying destination string printf("String after concatenation: %s\n", strncat(str1, str2, 5)); // this should be same as return value of strncat() printf("Destination String str1: %s", str1); return 0; } ``` 輸出: ```c String after concatenation: This is my initial string, add Destination String str1: This is my initial string, add ``` 正如您所看到的,在字符串`str1`的末尾只連接了字符串`str2`的 5 個字符,因為我們在 `strncat()`函數中將`count`指定為 5。 另一個**需要注意的重點是**這個函數返回指向目標字符串的指針,這就是為什么當我們顯示 `strncat()`的返回值時,它與目標字符串`str1`相同。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看