From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Working with time functions - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Working with time functions
- [Instructor] The computer keeps track of the time and so can your programs when you use the C library's time functions. The time function at line 8 fetches the time in the time_t variable now declared at line 6. The variables address is passed to the function, so the value returned is in the same variable. Both time and the time_t data type require the time.h header file, which is included in this code at line 2. Build and run. You were probably expecting to see the current date and time, but you are. This value is known as the UNIX Epoch, and it's the number of seconds that have ticked since January 1, 1970. Let's check out the last part of the value, 2182. Run again. And you see it's a new value, a new number of seconds has elapsed. Now you don't need to do all the math to convert the Epoch time into the current time. Instead this code uses the ctime function, the end of line nine inside the printf statement. This function is also prototyped in the time.h header file. And what it…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
Solving math puzzles3m 32s
-
Creating random numbers3m 42s
-
Working with time functions3m 54s
-
Sorting data4m 8s
-
Debugging your code2m
-
Using a debugger4m 53s
-
Writing your own header file2m 53s
-
Mixing multiple source code files4m
-
Challenge: Lotto simulation1m 18s
-
Solution: Lotto simulation2m 29s
-
-