Introduction to C Programming

15
Introduction to C Programming HOMEWORK 6

description

Introduction to C Programming. HOMEWORK 6. Homework 6-1 :字串輸入練習. 說明 由使用者在執行程式的時候,指定檔案名稱,程式由使用者指定檔案讀入內容, 將從檔案讀入的內容寫到字串當中, 再把內容輸出到螢幕上 Sample input C:\Users \Peter\ Desktop\test\bin\ Debug \hw-6-1.exe input.txt Content of input file - PowerPoint PPT Presentation

Transcript of Introduction to C Programming

Page 1: Introduction to C Programming

Introduction to C Programming

HOMEWORK 6

Page 2: Introduction to C Programming

Homework 6-1 :字串輸入練習• 說明

• 由使用者在執行程式的時候,指定檔案名稱,程式由使用者指定檔案讀入內容,將從檔案讀入的內容寫到字串當中,再把內容輸出到螢幕上

• Sample input• C:\Users\Peter\Desktop\test\bin\Debug\hw-6-1.exe

input.txt

• Content of input file• https://www.google.com.tw/search?q=foo+bar&ie=utf-8&oe=utf-8&aq=t

• Sample output• Read from: input.txt• The content of file:

• https://www.google.com.tw/search?q=foo+bar&ie=utf-8&oe=utf-8&aq=t

Page 3: Introduction to C Programming

Homework 6-2 : strtok 練習• 說明

• 由使用者在執行程式的時候,指定檔案名稱,程式由使用者指定檔案讀入內容,將從檔案讀入的內容寫到字串當中,再先把 Domain Name 和後面的參數切開存到靜態陣列。接下來再把後面的參數,利用「 ? 」切出服務名、利用「 & 」切出參數,依序切開後存到靜態陣列,最後再將存在靜態陣列當中的每個參數的內容輸出到螢幕上(輸出格式請使用投影片 Sample Output 的格式),並寫出總共有幾個參數

• Sample input• C:\Users\Peter\Desktop\test\bin\Debug\hw-6-2.exe

input.txt

• Content of input file• https://www.google.com.tw/search?q=foo+bar&ie=utf-8&oe=utf-8&aq=t

Page 4: Introduction to C Programming

Homework 6-2 : strtok 練習 (續)• Sample output

• Domain Name: www.google.com.tw• Service is “search”• No.1 argument is “q=foo+bar”• No.2 argument is “ie=utf-8”• No.3 argument is “oe=utf-8”• No. 4 argument is “aq=t”• ==============================• There are 4 arguments in this URL.

Page 5: Introduction to C Programming

Homework 6-3 : strcmp 練習• 說明

• 由使用者在執行程式的時候,指定檔案名稱,程式由使用者指定檔案讀入內容,將從檔案讀入的內容寫到字串當中,再先把 Domain Name 和後面的參數切開存到靜態陣列。接下來再把後面的參數,依序切開後存到靜態陣列,然後再利用 strcmp 去掃第一個字串,透過下面的服務列表,印出對應的服務名稱。

https://www.google.com.tw/search?q=foo+bar&ie=utf-8&oe=utf-8&aq=t

Page 6: Introduction to C Programming

Homework 6-3 : strcmp 練習

字串名稱 服務名稱

searchWeb Search

webhp

imghp Image Search

maps Map and Street View

nwshp News

Page 7: Introduction to C Programming

Homework 6-3 : strcmp 練習(續)• Sample input

• C:\Users\Peter\Desktop\test\bin\Debug\hw-6-3.exe input.txt

• Content of input file• https://www.google.com.tw/search?q=foo+bar&ie=utf-8&oe=utf-8&aq=t• https://www.google.com.tw/imghp?q=foo+bar&ie=utf-8&oe=utf-8&aq=t• https://www.google.com.tw/maps?q=foo+bar&ie=utf-8&oe=utf-8&aq=t• https://www.google.com.tw/nwshp?q=foo+bar&ie=utf-8&oe=utf-8&aq=t• https://www.google.com.tw/unknown?q=foo+bar&ie=utf-8&oe=utf-8&aq=t

• Sample output• No. 1 service is “Web Search”.• No. 2 service is “Image Search”.• No. 3 service is “Map and Street View”.• No. 4 service is “News”.• No. 5 service is unknown service.

Page 8: Introduction to C Programming

Homework 6-4 :字串上色• 說明

• 由使用者在執行程式的時候,指定檔案名稱,程式由使用者指定檔案讀入內容,將從檔案讀入的內容寫到字串當中,在輸出到螢幕上的時候,將 service 用亮藍色上色輸出,將「 ? 」、「 & 」等分界符號用亮紅色輸出,將參數用亮黃色輸出。

• Sample input• C:\Users\Peter\Desktop\test\bin\Debug\hw-6-4.exe

input.txt

• Content of input file• https://www.google.com.tw/search?q=foo+bar&ie=utf-8&oe=utf-8&aq=t

• Sample output• https://www.google.com.tw/search?q=foo+bar&ie=utf-8&oe=utf-8&aq=t

Page 9: Introduction to C Programming

Homework 6-4 Hint :色碼

參考資料: http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html

Page 10: Introduction to C Programming

Homework 6-4 Hint :色碼• 輸出結果:

Page 11: Introduction to C Programming

Homework 6-5 : strstr 練習• 說明

• 由使用者在執行程式的時候,指定檔案名稱,程式由使用者指定檔案讀入內容,將從檔案讀入的內容寫到字串當中,再先把 Domain Name 和後面的參數切開存到靜態陣列。接下來再把後面的參數,利用「 ? 」切出服務名、利用「 & 」切出參數,依序切開後存到靜態陣列,最後在從「 q=keyword 」參數當中,取出待找的keyword ,然後再從待找檔案( database.txt )當中,去找出keyword 所在,若有找到,列出找到 keyword 幾次、並印出第一個keyword 出現的位置與其後面的 15 個字元。

Page 12: Introduction to C Programming

Homework 6-5 : strstr 練習• Sample input

• C:\Users\Peter\Desktop\test\bin\Debug\hw-6-5.ext input.txt

• Content of input file• https://www.google.com.tw/search?q=ARM&ie=utf-8&oe=utf-8&aq=t

Page 13: Introduction to C Programming

Homework 6-5 : strstr 練習• 待找檔案( database.txt )的內容

In a typical hypervisor, there are three major compo- nents: CPU virtualization, memory virtualization, and I/O virtualization. For CPU virtualization, ARMvisor uses traditional “trap and emulate” to deal with sensi- tive instructions. Since there is no hardware support for virtualization in ARM architecture V6 and earlier, we have to patch the guest OS to force critical instructions to trap. For memory virtualization, the functional- ity of the MMU, which translates a guest virtual address to host physical address, is emulated. In ARMvisor, a shadow page table is dynamically allocated to avoid the inefficiency and inflexibility of static allocation for the guest OSes. In addition, ARMvisor uses R-Map to take care of protecting the memory space of the guest OS. For I/O virtualization, ARMvisor relies on QEMU to emulate I/O devices. We have implemented KVM on ARM-based Linux kernel for all three components in ARMvisor. At this time, we can successfully run a guest Ubuntu system on an Ubuntu host OS with ARMvisor on the ARM-based TI BeagleBoard.

Page 14: Introduction to C Programming

Homework 6-5 : strstr 練習• Sample output

• The keyword “ARM” has been found for 9 times.• It has been found for the first time in “ARMvisor uses trad”

Page 15: Introduction to C Programming

Deadline

•12/13