c語言 library 的問題


Create a library. The library should contain two functions, Hello() and World(). Calling the Hello() function should print out the string "Hello"; calling the World() function should print out the string "World".

------就是用c創造一個 library > Hello 跟World 呼叫的話就各印出來一次

The library should use a flag (implemented using a static global variable) that keeps track of which string was last printed. A call to the Hello() function should print out "Hello" only if "World" was the last string printed, and vice versa.

------- library 要有flag (不知道是不是註記的意思) Hello() 跟World ()要交互列印,(不能Hello()自己印兩遍) ------->很不確定

The flag should be updated at the end of each function call. Each function should return 1 if the string was printed, 0 otherwise. Write a simple program that uses the library and tests for the correct working of the functions.

-------- 呼叫這個 function 就會回傳 1 印完了就會回傳0


1 Answer

  • 7 years ago
    Favorite Answer

    flag 是個確定執行狀況的變數 舉個例子:回傳值的0,1,... 都是回傳值的flag

    0代表成功.. 其他代表失敗..每個都還有不一樣的失敗訊息


    只有當world是最後的字串 才會印出hello 反之亦可

    第三段要求每一次呼叫函數後要更新flag 如果字串有印出來 都要回傳1


    編寫一個簡單的程式 運用hello和world函數 並測試它們是否正確運行

    有關flag 請參考


Still have questions? Get your answers by asking now.