- Write a C program which reads strings from stdin and if a string is consisted of digits, it is treated as a number. Sum all the numbers and write sum to stdout.
- The reading is terminated by end of file, that is, a ctrl-D.
- The length of each string does not exceed 16.
- You may assume the numbers and the sum can be handled with int.
- For converting a string to a number, you may consult strtol().
- For example:
$ gcc ex1-sum-stdin.c $ ./a.out I have 1000 You have 200 I give you 50 Now You have 250. <---- ctrl-D pressed 1250 <---- only 1000, 200, 50 are summed $ ./a.out 100 + 23 = 123 $100 - 23 = 77. <---- ctrl-D pressed 269 <---- 100, 23, 123, 23 are summed
My program:
https://ideone.com/V3fc8b
https://ideone.com/hFVjyY
2021年3月3日 星期三
Unix System Programming (1092)-exer1
exercise 1: a simple C program
訂閱:
張貼留言 (Atom)
-
KDE Plasma 桌面環境安裝中文輸入法 hime 或 gcin 無法切換輸入法解決方式如下: 1. kubuntu 20.04 預設是沒有語系支援 (Language Support) 的,須自行安裝,打開終端機輸入: sudo apt install languag...
-
學習一種新的語言最快的方式莫過於實際的應用,TSK map 是晶片測試結果的紀錄檔,裡面 紀錄了每一個 die 的測試結果還有相關的資訊,檔案是以Binary的方式紀錄,今天就介紹用 Julia 來讀取並將內容展開。 下面是 map format 的說明書,其中map fi...
-
當我們將資料匯出成 csv 檔後再用Excel開啟會發現數字前綴0會無法顯示,但是用文字編輯軟體去看檔案內容其實是包含0的,要解決這個問題方法如下: 1. 首先不要用開啟檔案的方式,於檔案下拉選單選擇【匯入】: 匯入檔案類型點選【文字檔】: 2. 選擇【分隔符號】: 3....
沒有留言:
張貼留言