看板 b89902xxx 關於我們 聯絡資訊
第四次作業:Simple Text Editor 繳交期限: 2002/4/23 晚上12:00前,遲交一天扣3%分,最後繳交期限為2002/5/7,超過此日期 而未繳交的以0分計算。 負責助教: 李佳穎 cylee@csie.ntu.edu.tw 目標: 編寫一個可輸入、有append、insert(或delete)功能的簡單文字編輯程式。 指令格式: my_editor operand1 [operator] [operand2] operand1: 為一個text file的 file_name operator: -ap, -in or –de operand2: 為一個正整數n 功能: <Basic> (85%) 1. 當使用者只加operand1、不加任何operator時,讓使用者在螢幕輸入文字, 按ctrl+d後存入file_name所指定的檔案中。(50%) 2. –ap: 當使用者加上-ap時,先輸出原來檔案內容至file_name所指定的檔案 ,然後讓使用者在螢幕輸入文字,按ctrl+d後append新的內容至原檔案。(15%) 3. –in: 當使用者加上-in時,先輸出原來檔案內容至file_name所指定的檔案, 然後讓使用者在螢幕輸入文字,按ctrl+d後insert新的內容至第n字之後並存 回原檔案。若使用者沒有指定operand2(即n),則功能和append相同。(20%) <Optional> (15%) 1. –de: 當使用者指定operand及加上-de時,先輸出原來檔案內容至file_name所指定 的檔案,然後delete第n字並存回原檔。若使用者沒有指定operand2,則不做 任何修改。 要求: 要使用tmpfile() 先create一個temporary file,再處理對檔案的修改,然後將它 rename成file_name。rename()請參考課本第四章。 規則: 請把所有程式碼寫在fun.c裡面(把這個函數當成main一樣就行了) 範例: 1. my_editor hello.txt 將使用者在螢幕上輸入的字元存到檔案hello.txt。 2. my_editor hello.txt –ap 將使用者在螢幕上輸入的字元append到檔案hello.txt。 3. my_editor hello.txt –in 5 將使用者在螢幕上輸入的字元insert到第5個字元後。 4. my_editor hello.txt –in 和 my_editor hello.txt –ap 功能相同。 5. my_editor hello.txt –de 10 把hello.txt中的第10個字元刪除。 6. my_editor hello.txt –de 沒任何功能。 注意事項: 1. 這次作業的測試機器一樣是140.112.28.110,請大家要telnet到這台機器上去 測試一下作業。 2. 上次繳交第三次作業時,發現有位同學放了1.xGB大小的檔案到140.112.28.110 這台機器上,導致其他同學無法交作業。請大家以後寫作業時避免這種情況 發生,否則將酌以扣分,若屬惡意、情節嚴重者將交由系上處理。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.29.220