對單詞長度直方圖理解有錯,下面代碼是直接打印出了每個單詞的長度。
真正的單詞長度直方圖應該是長度爲某個數的單詞數多少。
就如圖像處理中的灰度直方圖,講的是對應灰度的像素數多少。
// 單詞長度的水平直方圖 #include <stdio.h> #define WORDS_NUBMER 100 // 輸入的最多單詞數 #define IN 1 // inside a word #define OUT 0 // outside a word int main() { int i, j, c, state, nw; int nchword[WORDS_NUBMER] = {0}; // 數組中的數存放遇到的單詞中的字符數 state = OUT; nw = 0; // 統計單詞數 while ((c = getchar()) != EOF) { if (c == ' ' || c == '/t' || c == '/n') { if (state == IN) { state = OUT; // 在單詞外 } } else if (state == OUT) // 出現某個單詞的首字符 { ++nchword[nw]; ++nw; state = IN; } else // 單詞除過首字符的其他字符 { ++nchword[nw-1]; // 數組從0開始計數 } } // 輸出直方圖 for (i = 0; i < nw; i++) { printf("Word NO%2d: ", i); for (j = 0; j < nchword[i]; j++) { printf("| "); } printf("/n"); } return 0; }
模擬實現通訊錄(文件存儲) 題目要求: 實現一個通訊錄,通訊錄可以實現文件存儲每個人的信息,包括:姓名、性別、年齡、電話、住址 實現功能:1.添加聯繫人信息 2.刪除指定聯繫人信息3.查找指定聯繫人信息 4.修
#include <stdio.h> #define TABINC 8 // tab length; int main() { int c, nb, pos; nb = 0; // number of blanks
輸出部分與單詞個數直方圖類似。 // 字符出現頻率的直方圖 #include <stdio.h> #include <ctype.h> #define MAXHIST 15 // max length of histogram #defi
製表符的真實含義:它不是每次都移動8個空白字節,而是對從一行開始,或者是一次輸入tab鍵結束,就開始爲下一次做準備了。所以在一個tab鍵結束,此行的之前字節數剛好是8的倍數,一個tab鍵中的非空白字節可以通過已有字節模8得到。 假設
// 顛倒字符串中的字符順序 #include <stdio.h> #define MAXLINE 1000 // maximum input line length int getline(char s[], int lim
// 獲取最長文本行 #include <stdio.h> #define MAXLINE 1000 // maximum input line length #define LENLINE 80 // line leng
// Count characters, words, and lines in input // Output the words in different lines #include <stdio.h> #define IN 1
// 刪除行末的空格及製表符,並刪除全是空格的行 #include <stdio.h> #define MAXLINE 1000 // maximum input line length int getline(char l
今天C語言的學習小結 第一.函數這章當中4.4作用域規則。 首先我們可以懷着這幾個問題去看,*1如何進行聲明才能確保變量在編譯時被正確聲明?*2如何安排聲明的位置才能確保程序在加載時各部分能正確連接?*3如何組織程序中的聲明才能確保只有
轉載於 http://www.360doc.com/content/12/0504/15/9400799_208611794.shtml #include<stdlib.h> void exit(int status);不像fork那麼
1、C語言之父是Dennis Ritchie,他也是UNIX操作系統發明者之一。 2、C89標準,ANSI制定的第一個C語言標準,在1989年被正式採用,故稱C89,也稱ANSI C。 該標準隨後ISO採納,成爲國際標準(ISO/I