1.解題思路
首先要先讀取檔案,然後呼叫函式實現返回檔案的字元數,行數,單詞總數。用的是c#來做。
主要實現的功能:
wc.exe -c mrhu.txt //返回檔案 mrhu.txt 的字元數
wc.exe -w mrhu.txt //返回檔案 mrhu.txt 的單詞總數
wc.exe -l mrhu.txt //返回檔案 mrhu.txt 的總行數
2,主要**說明
讀取檔案
static void main(string args)
// 獲取檔名
string sfilename = arrmesssplit[length - 1];
wc wc = new wc();
wc.operator(sparameter, sfilename);
wc.basecount(sfilename);
wc.display();
wc.s**eresult();
}統計行數,字元數,單詞數
public void basecount(string filename)
', '(', ')', '+' ,'-',
'*', '='};
while ((nchar = sr.read()) != -1)
}if (nchar == '\n')
}icharcount = charcount;
iwordcount = wordcount + 1;
ilinecount = linecount + 1;
sr.close();
}catch (ioexception ex)
輸出public void s**eresult()
字元數:", sfilename, icharcount);
if (a == "-w")
f.writeline("單詞數:", sfilename, iwordcount);
if (a == "-l")
f.writeline("行數:", sfilename, ilinecount);
}f.close();
console.readkey();
}public void display()
", icharcount);
}else if (s == "-w")
", iwordcount);
}else if (s == "-l")
", ilinecount);}}
console.writeline();
3.測試
5.參考文獻
用C 實現檔案I O操作
檔案 i o 在c 中比烤蛋糕簡單多了。在這篇文章裡,我會詳細解釋ascii和二進位制檔案的輸入輸出的每個細節,值得注意的是,所有這些都是用c 完成的。一 ascii 輸出 為了使用下面的方法,你必須包含標頭檔案 譯者注 在標準c 中,已經使用取代 fstream.h 所有的c 標準標頭檔案都是無字...
用C讀取json檔案
a jconf t read jconf const char file 確定檔案大小,並將讀取指標移回檔案開始 fseek f,0,seek end long pos ftell f fseek f,0,seek set if pos 0 if pos max conf size 根據檔案大小申請...
用C讀取json檔案
a jconf t read jconf const char file 確定檔案大小,並將讀取指標移回檔案開始 fseek f,0,seek end long pos ftell f fseek f,0,seek set if pos 0 if pos max conf size 根據檔案大小申請...