Groups
Groups
Sign in
Groups
Groups
中正資工,系統程式設計
Conversations
About
Send feedback
Help
作業四pseudo code疑問
130 views
Skip to first unread message
中正資工,系統程式設計
unread,
Mar 25, 2021, 10:55:30 PM
3/25/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 中正資工,系統程式設計
教授好,不好意思我對pseudo code裡面有一些東西不太了解,想要詢問一下:
1.為什麼要setvbuf(input)呢? 對input不是要讀取而已嗎,為什麼還需要設buffer?
2.想請問linePos這一個變數是在做什麼的,因為我看它在pseudo code裡面好像值都不會變
3.想確認一下讀到換行符號是要忽略等到滿80個字母再換行,還是就直接換行呢?
奉天承運本宅 曰
unread,
Mar 26, 2021, 3:58:36 AM
3/26/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 中正資工,系統程式設計
1. 因為libC會把資料先讀到buffer,因此我們用gerchar才可以一個一個字元讀入,否則disk是block device,一次讀入就是4096
2. linePos是記錄目前輸出到第幾個字了,一行只能放80個字,如果要輸出一個英文單字,那麼『「輸出的字的長度+linePos+1」>80』,那麼就要換行才能輸出單字,『加1』是因為單字間要用『空白』隔開
3. 直接換行
習五
中正資工,系統程式設計 在 2021年3月26日 星期五上午10:55:30 [UTC+8] 的信中寫道:
中正資工,系統程式設計
unread,
Mar 26, 2021, 4:11:51 AM
3/26/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 中正資工,系統程式設計
那麼對input跟output所設定的setvbuf(FILE *stream, char *buffer, int mode, size_t size),在第二個參數那裡,是要分別填入不同的buffer嗎?
奉天承運本宅 曰 在 2021年3月26日 星期五下午3:58:36 [UTC+8] 的信中寫道:
中正資工,系統程式設計
unread,
Mar 26, 2021, 5:31:11 AM
3/26/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 中正資工,系統程式設計
教授不好意思,還是不太瞭解第1點,要從一個檔案讀取字元不是用getc嗎?
且我用以下程式碼(沒有對input做setvbuf)來測試,getc是可以得到一個一個字元的。
奉天承運本宅 曰 在 2021年3月26日 星期五下午3:58:36 [UTC+8] 的信中寫道:
1. 因為libC會把資料先讀到buffer,因此我們用gerchar才可以一個一個字元讀入,否則disk是block device,一次讀入就是4096
奉天承運本宅 曰
unread,
Mar 26, 2021, 7:27:23 AM
3/26/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 中正資工,系統程式設計
那是因為libc預設的buffer size是1024B或4096B,如果你用setvbuf修改buffer size會得到不一樣的效果(速度方面,可以使用strace看一下system call的次數)
中正資工,系統程式設計 在 2021年3月26日 星期五下午5:31:11 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages