2007年8月19日 星期日

qsort運用(II)

以下範例是將一個 integer 陣列做 qsort:
int compare(const void *pa,const void *pb);

int main(){
qsort(diff,num-1,sizeof(int),compare);
}

int compare(const void *pa,const void *pb){
int a,b;
a=*(int *)pa;
b=*(int *)pb;
if(a < b)
return -1;
}
else if(a==b){
return 0;
}
else{
return 1;
}
}
qsort限制比較函式中,所傳參數必須為(const void *, const void*)也就是一個 void 指標,在 compare 函式中,不能直接拿*pa和*pb來作比較,會出現有關void的blabla...錯誤,因此必須轉為其他型態,先以(int *)強制轉型為 int 指標,再利用 * 運算子來存取儲存於其中的 integer,便可成功編譯。

2007年8月6日 星期一

Using long long with MinGW

long long是 C99的標準,可以處理-((2^63)-1)~(2^63)-1的數字,正常使用方法是 %lld /u/x,但如果使用MinGW來編譯的話,必須用%I64d /u/x 才能正常使用

The printf() implementation used by MinGW (which is provided by msvcrt.dll) uses its own format specifier for 64-bit integers as documented in MSDN: http://msdn.microsoft.com/library/en-us/vccore98/HTML/_crt_size_and_distance_specification.asp. For example, %I64d will format a (decimal) long long and %I64u will format an unsigned long long.

參考資料:http://www.mingw.org/MinGWiki/index.php/long%20long

2007年7月31日 星期二

832 Financial Risk

題目網頁:http://acm.uva.es/p/v8/832.html

這是我目前做過最心機的題目了,重點在於最後幾句
Your program must write the percentage of uncovered risk, truncated to 2 fractional digits.
原本以為用 %.2lf%% 就可以解決,上傳了10幾遍還是沒辦法,靈機一動才想到這幾句話的意思...

有可能的Output: 30%、11.85%、10.6%

2007年7月25日 星期三

利用 Filezilla 連接 SFTP

使用環境:Windows+Filezilla Portable(隨身碟)
  1. 進入Filezilla的站台管理員,新增一站台,輸入主機名稱(port會自行調整),伺服器型態選擇 "SFTP使用SSH2"輸入 使用者名稱 與 Account ,即可連線。
  2. 利用之前不需輸入帳號密碼便可登入SSH做出來的Key,首先到Putty作者的網頁下載Pageant,執行後,畫面右下角會出現Pageant的圖示,選擇 add key 匯入之前的.ppk檔,輸入passphrase,連線後Filezilla一樣會跳出要求密碼的視窗,再次輸入passphrase,即可登入。

參考資料:
http://filezilla-project.org/wiki/index.php/Howto

2007年7月24日 星期二

一些有關 C 語言的連結

C Standard Library:
http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html

裡面包含了C99才加入的lib,不過說明比較少,平常用的話,我比較喜歡 Eric Huss 1997年寫的

The C Reference Guide:
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

雖然是比較舊的版本,但是說明比較詳細,有些還會附範例,我直接存到電腦裡,要寫的時候直接開起來看。

FAQ:

http://c-faq.com/

Infrequently Asked Question:
http://www.plethora.net/~seebs/faqs/c-iaq.html


裡面有些問題還挺有趣的,平時不會想到,有空可以研究研究。