本程序实现了每隔1秒钟便输出当前系统时间。
#include
gboolean show_time(gpointer data);
int main(int argc,char** argv){
GMainLoop* main_loop = NULL;
guint i = 0;
main_loop = g_main_loop_new(NULL,FALSE);
g_timeout_add_seconds(1,(GSourceFunc)show_time,NULL);
g_main_loop_run(main_loop);
g_main_loop_quit(main_loop);
return 0;
}
gboolean show_time(gpointer data){
GTimeVal now;
g_get_current_time(&now);
struct tm* time_now;
time_now = localtime(&now.tv_sec);
gchar time_str[256] = {0};
strftime(time_str,256,"%Y-%m-%d %H:%M:%S",time_now);
g_print("%s\n",time_str);
return TRUE;
}
阅读(3068) | 评论(0) | 转发(0) |