lecture21 - Last time Chapter 15, Input/output functions...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Low-Level Programming Concepts CMSC 212 ecture 21 1 CMSC 212 Lecture 21 November 10, 2009 Last time Chapter 15, Input/output functions – error handling, and terminating execution – the FILE * type, and the standard streams stdin , stdout , and stderr – opening and closing files – text streams: character-oriented I/O, line-oriented I/O, and formatted I/O 2 CMSC 212 – binary streams Chapter 16, Standard library – random numbers – the math library assert () Reading 3 CMSC 212 Chapter 16, Standard Library, con't. 4 CMSC 212
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Time There are many ways to measure time on a computer Conceptual difference: wall time process time Difference in how to measure terval time 5 CMSC 212 – interval time – clock cycles What time to use depends on what is being measured and why the measurements are being done Representing time-of-day computationally How to deal with – time zones – daylight savings times – computers moving time zones – leap seconds? nswer: 6 CMSC 212 Answer: – UNIX keeps time internally as seconds and fractions of a second- 2 32 bit values work nicely for 1ns accuracy for over 100 years – UNIX uses a reference starting point called the epoch , which is midnight, 1/1/1970 – keep all times in UTC form internally, meaning there are no time zones or daylight savings time to deal with Date and time types in <time.h> Most C functions having to do with time use a type time_t (an integer type) that contains an encoded representation of a time Some use the following tm structure that has fields that can be extracted from a time_t variable: struct tm { 7 CMSC 212 int tm_sec; /* seconds */ int tm_min; /* minutes */ int tm_hour; /* hours */ int tm_mday; /* day of the month */ int tm_mon; /* month */ int tm_year; /* year */ int tm_wday; /* day of the week */ int tm_yday; /* day in the year */ int tm_isdst; /* daylight saving time */ }; Date and time functions in <time.h> clock_t clock(void); – returns the process time since the start of program execution – to convert to time, divide by CLOCKS_PER_SEC (defined in time.h ) time_t time(time_t *val); – fills val with the current time (in an implementation-dependent format) har * time ime_t al ; 8 CMSC 212 char *ctime(time_t *val); – returns a character representation of the passed time – example: Tue Nov 10 09:02:48 2009\n\0 double difftime(time_t time1, time_t time2); – returns the number of seconds between time1 and time2 struct tm *gmtime(time_t val); struct tm *localtime(time_t val); – converts a time to UTC or local time, in the form of a struct tm
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

lecture21 - Last time Chapter 15, Input/output functions...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online