<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # C 程序:使用指針計算字符串中的元音和輔音 > 原文: [https://beginnersbook.com/2019/02/c-program-to-count-vowels-and-consonants-in-a-string-using-pointer/](https://beginnersbook.com/2019/02/c-program-to-count-vowels-and-consonants-in-a-string-using-pointer/) 在本教程中,我們將編寫一個 C 程序,使用指針計算給定字符串中的元音和輔音。 要了解這個程序,你應該知道[數組](https://beginnersbook.com/2014/01/c-arrays-example/)和[指針在 C](https://beginnersbook.com/2014/01/c-pointers/) 中的基礎知識。 ## 使用指針計算字符串中的元音和輔音的程序 在下面的程序中,我們聲明了一個`char`數組`str`來保存輸入字符串,我們使用`fgets()`函數將其存儲在數組中。我們已經將數組的基址(第一個元素的地址)賦給指針`p`。我們在[`while`循環](https://beginnersbook.com/2014/01/c-while-loop/)中使用指針`p`瀏覽輸入字符串的所有字符,并在每次迭代時遞增指針值。 ```c #include <stdio.h> int main() { char str[100]; char *p; int vCount=0,cCount=0; printf("Enter any string: "); fgets(str, 100, stdin); //assign base address of char array to pointer p=str; //'\0' signifies end of the string while(*p!='\0') { if(*p=='A' ||*p=='E' ||*p=='I' ||*p=='O' ||*p=='U' ||*p=='a' ||*p=='e' ||*p=='i' ||*p=='o' ||*p=='u') vCount++; else cCount++; //increase the pointer, to point next character p++; } printf("Number of Vowels in String: %d\n",vCount); printf("Number of Consonants in String: %d",cCount); return 0; } ``` **輸出:** ![C Program to Count Vowels and Consonants in a String using Pointer](https://img.kancloud.cn/f4/ee/f4eef4f3edc6d82f68fa902e0a17e84e_834x284.jpg) #### 相關 C 示例 1. [C 程序:使用指針打印字符串](https://beginnersbook.com/2019/02/c-program-to-print-string-using-pointer/) 2. [C 程序:用指針交換兩個數字](https://beginnersbook.com/2019/02/c-program-to-swap-two-numbers-using-pointers/) 3. [C 程序:創建初始化和訪問指針變量](https://beginnersbook.com/2019/02/c-program-to-create-initialize-and-access-a-pointer-variable/)
                  <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>

                              哎呀哎呀视频在线观看