Subject:C Programming Unit 4: C Header Files

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Subject:C programming

Unit 4: C Header Files:

Topics Covered:
1. time.h
2. stdlib.h
3. String.h

Submitted by,
Name: Kartavya Lajpal
Enrolment No:05817711922
Branch andSemester: AI&DS-Section-A, Ist Sem. Date:
01. time.h
The time.h header defines four variable types, two macro and various
functions for manipulating date and time.

NULL CLOCKS_PER_SEC

This macro is the value of This macro represents


a null pointer constant. the number of processor
clocks per second.
Library Variables

1 2 3

clock_t time_t Struct tm

clock_t which is a part of the clock_t represents the date as struct tm holds the date and
calendar time represents the an integer which is a part of time.
date as an integer. the calendar time
Pre-defined Functions in
time.h

asctime() ctime()
This function returns the date and clock() This function returns the date
difftime()
time in the format This function returns and time in the format This function returns
day month date day month
hours:minutes:seconds year. the processor time hours:minutes:seconds year
the difference
Eg: Sat Jul 27 11:26:03 2019.
asctime() function returns a string
consumed by a Eg: Sat Jul 27 11:26:03 2019 between the times
time is printed based on the
by taking struct tm variable as a program pointer returned by Calendar
provided.
parameter.


Time

gmtime() mktime() time() strftime()


This function prints the UTC This function helps to
(Coordinated Universal Time) Time
This function returns This function returns
the calendar-time format the string
and date. the calendar-time returned by other time
Format for both gmtime() and equivalent using struct
asctime() is same equivalent using data- functions using
tm.

type time_t. different format
or commercial use specifiers

Programming Code:
Output:
01. stdlib.h
stdlib.h is the header of the general purpose standard library of C programming language which
includes functions involving memory allocation, process control, conversions and others. It is
compatible with C++ and is known as cstdlib in C++. The name "stdlib" stands for "standard
library".

NULL EXIT_FAILURE EXIT_SUCCESS RAND_MAX

This macro is the value of This is the value for the This is the value for the This macro is the
a null pointer constant. exit function to return in exit function to return in maximum value returned
case of failure. case of success. by the rand function.

MB_CUR_MAX

This macro is the maximum number of bytes in a multi-byte


character set which cannot be larger than MB_LEN_MAX.

Programming Code:
Output:
01. string.h
The string.h header defines one variable type, one macro, and various functions for
manipulating arrays of characters.
Macros

NULL

This macro is the value of


a null pointer constant.
Pre-defined Functions in
string.h

void *memchr(const void *str, int int memcmp(const void *str1, void *memcpy(void *dest, void *memmove(void *dest,
c, size_t n) const void *str2, size_t n) const void *src, size_t n) const void *src, size_t n)
Searches for the first occurrence Copies n characters from src Another function to copy n
Compares the first n bytes of
of the character c (an unsigned characters from str2 to str1.
char) in the first n bytes of the str1 and str2. to dest.
string pointed to, by the argument

str.
Programming Code;
Output:

Output 1:

ope

Output 2:

Output 3:

Source string = Hello


Target string = He
thank you!

You might also like