- ctime
インクルードファイル time.h 書式 char *ctime(time_t *timer) 引数 カレンダ時間へのポインタ 処理 カレンダ時間を文字列(日付)に変換 戻り値 日付文字列 - time
インクルードファイル time.h 書式 time_t time(time_t *timer) 引数 カレンダ時間格納領域へのポインタ 処理 現在のカレンダ時間の取得 戻り値 現在のカレンダ時間 この日付の関数を利用すると先程の乱数の発生に利用できる。
/*** 日付表示 ***/ #include <stdio.h> #include <time.h> int main(void){ time_t now; now = time(NULL); /* 現在時刻の取得 */ printf("%s", ctime(&now)); /* ローカルタイムの表示 */ }
/*** 乱数を発生させる2 ***/ #include <stdio.h> #include <stdlib.h> #include <time.h> int main(void){ int i, ran; time_t now; srand((int) time(NULL)); /* 乱数の種(元になる数)を生成 */ for (i=0; i<10; i++){ ran = rand(); printf("乱数 %2d: %10d\n", i+1, ran); } }2002年12月18日 12:16 更新