Sams Teach Yourself C in 21 Days

(singke) #1
13: /* Record the time the program starts execution. */
14:
15: start = time(0);
16:
17: /* Record the current time, using the alternate method of */
18: /* calling time(). */
19:
20: time(&now);
21:
22: /* Convert the time_t value into a type tm structure. */
23:
24: ptr = localtime(&now);
25:
26: /* Create and display a formatted string containing */
27: /* the current time. */
28:
29: c = asctime(ptr);
30: puts(c);
31: getc(stdin);
32:
33: /* Now use the strftime() function to create several different */
34: /* formatted versions of the time. */
35:
36: strftime(buf1, 80, “This is week %U of the year %Y”, ptr);
37: puts(buf1);
38: getc(stdin);
39:
40: strftime(buf1, 80, “Today is %A, %x”, ptr);
41: puts(buf1);
42: getc(stdin);
43:
44: strftime(buf1, 80, “It is %M minutes past hour %I.”, ptr);
45: puts(buf1);
46: getc(stdin);
47:
48: /* Now get the current time and calculate program duration. */
49:
50: finish = time(0);
51: duration = difftime(finish, start);
52: printf(“\nProgram execution time using time() = %f seconds.”,
➥duration);
53:
54: /* Also display program duration in hundredths of seconds */
55: /* using clock(). */
56:
57: printf(“\nProgram execution time using clock() = %ld hundredths of
➥sec.”,
58: clock());
59: return 0;
60: }

542 Day 19

LISTING19.2 continued

30 448201x-CH19 8/13/02 11:20 AM Page 542

Free download pdf