亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C語言新手問題!

C語言新手問題!

C
知邪 2017-07-08 02:15:39
#include<stdio.h>#include<stdbool.h>#include<ctype.h>#define STOP '|'int main(void){ char c; // 讀入字符? char prev; //讀入的前一個字符? long n_chars = 0L;//字符數? int n_lines = 0;//行數? int n_words = 0;//單詞數? int p_lines = 0;//不完整的行數? bool inword = false;//如果C在單詞中,inword 等于true printf("Enter text to be analyzed (| to terminate):"); 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') ? p_lines = 1; printf("characters = %ld, words = %d, limes = %d,",n_chars,n_words,n_lines); printf("partial lines = %d\n",p_lines); return 0;}輸入:?Reason is apowerful servant butan inadequate master.|問:從while開始,這個循環是 從輸入的內容中 一個字符一個字符的循環一遍?還是直接整體開始循環的?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 1399 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號