list_17_11.c

来自「This source code has been tested under O」· C语言 代码 · 共 70 行

C
70
字号
/*************************************************************************                                                                    ****  listing_17_11.c                                                   ****                                                                    ****  Workproc example. This program presents a simple label, just to   ****  provide a window. Its real operation is a workproc, which counts  ****  the number of times it's called each second, and prints both the  ****  immediate count and an average.                                   ****                                                                    *************************************************************************/#include <Xm/Label.h>Boolean	WorkProc();			/* FORWARD Definitions	      */Widget	appshell,	the_label;void main( argc, argv )    int     argc;    char    *argv[];{    appshell = XtInitialize( argv[0], "Listing_17_11", NULL, 0, &argc, argv );    the_label = XmCreateLabel( appshell, "TheLabel", NULL, 0 );    XtManageChild( the_label );    XtAddWorkProc( WorkProc, NULL );    XtRealizeWidget( appshell );    XtMainLoop();}Boolean WorkProc( ignore )    caddr_t	ignore;{    static int	tot_calls = 0,		/* Total calls                */		tot_time  = 0,		/* Total time running	      */                calls_sec = 0,          /* Calls this second          */		last_time = 0;          /* Time of last call          */    int		this_time = time(NULL);    if (last_time == 0)        last_time = this_time;    else if (last_time == this_time) 	{	tot_calls++;	calls_sec++;	}    else	{	tot_time++;	printf( "Second %d\n", tot_time );	printf( "   Calls     = %6d\n", calls_sec );	printf( "   Avg Calls = %6.1f\n", ((float)tot_calls)/tot_time );	calls_sec = 0;	last_time = this_time;	}    return( FALSE );}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?