- 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...
-
編輯套件來源檔: sudo vim /etc/apt/sources.list 加入下面來源位址: deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse de...
-
當使用 apt 安裝軟體時出現下面的訊息: $ sudo apt-get install <package> Reading package lists... Done Building dependency tree Reading state inf...
沒有留言:
張貼留言