低級IO - read

不需要標準庫的 scanf 等函數,而是直接調用 unix 系統低級IO函數 read。
實現:將任意輸入複製到任意輸出。

代碼如下:

int main() {
        char buf[5];
        int n;

        while ((n = read(0, buf, 5)) > 0) {
                write(1, buf, n);
        }
        return  0;
}

運行效果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章