日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

程序2:word count

發布時間:2023/11/30 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 程序2:word count 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本程序改變自:http://blog.csdn.net/zhixi1050/article/details/72718638

語言:C++

編譯環境:visual studio 2015

運行環境:Win10

做出修改的地方:在原碼基礎上修改了記錄行數的功能,刪去了不完整行數的記錄,直接顯示行數。

修改后的代碼如下:

#include <stdio.h>
//#include <stdlib.h>
#include <ctype.h>//為isspace()提供原型
#include <stdbool.h>
#define STOP '|' //定義結束標志


int main(void)
{
?? ?char c;
?? ?char prev;//讀取的前一個字符
?? ?long n_chars = 0L;??????//字符數
?? ?int n_lines = 0;????? ? ? ? //行數
?? ?int n_words = 0;???? ? ?? //單詞數
?? ?bool inword = false;??????//字符在單詞中,inward等于ture

?? ?printf("請輸入字符( | 用于結束輸入):\n");
?? ?prev = '\n';//識別完整的行

?? ?while ((c = getchar()) != STOP)??????//當讀取的字符不為結束字符時
?? ?{
?? ??? ?n_chars++??????;//統計字符數

?? ??? ?if (c == '\n')
?? ??? ??? ?n_lines++;??????//統計行

?? ??? ?if (!isspace(c) && !inword)
?? ??? ?{
?? ??? ??? ?inword = true;??????//開始一個新單詞;
?? ??? ??? ?n_words++;??????//統計單詞
?? ??? ?}
?? ??? ?if (isspace(c) && inword)
?? ??? ??? ?inword = false;??????//打到單詞的結尾
?? ??? ?prev = c;
?? ?}

?? ?if (prev != '\n')
?? ??? ?n_lines ++;
?? ?printf("字母數目=%ld,單詞數=%d,行數=%d,", n_chars, n_words, n_lines);
?? ?return 0;
}

轉載于:https://www.cnblogs.com/nictang/p/7561022.html

總結

以上是生活随笔為你收集整理的程序2:word count的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。