[問題] line counting

看板C_and_CPP (C/C++)作者 (linada)時間11年前 (2015/02/17 11:07), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) GCC 問題(Question): 執行後,無法測試出是否有newline, tabs, blanks,結果都為0 DOS介面的EOF指令除了control-z 還有? 餵入的資料(Input): I like programming and surfing on the ptt. All the output are zeros. Please help me. ^z 預期的正確結果(Expected Output): newlines:3 blanks:12 tabs:1 程式碼(Code):(請善用置底文網頁, 記得排版) int main (void) { int c, newlines, blanks, tabs; int done = 0; newlines = 0; blanks = 0; tabs = 0; while( c = getchar() != EOF) { if ( c == '\n') newlines++; if ( c == ' ') ++blanks; if ( c == '\t') ++tabs; } printf ("newlines:%d\nblanks:%d\ntabs:%d\n", newlines, blanks, tabs); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 221.120.4.224 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1424142439.A.530.html

02/17 11:20, , 1F
c = getchar() => (c = getchar()) 加上括弧
02/17 11:20, 1F

02/17 11:24, , 2F
感謝!!!
02/17 11:24, 2F
文章代碼(AID): #1Kuh1dKm (C_and_CPP)
文章代碼(AID): #1Kuh1dKm (C_and_CPP)