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

Republic of the Philippines

City of Olongapo
GORDON COLLEGE
Olongapo City Sports Complex, East Tapinac, Olongapo City
College of computer studies

NAME: Rachelle Ann E. De Felix DATE: August 22, 2022


PROGRAM-Yr. Level-Block: BSIT-1C

C Standard Libraries and Functions

Name of C Library Example of Function Description and


Standard Library Description Functions Syntax

1. malloc() This function is used to


allocate space in memory
during the execution of the
program.
Syntax: void *malloc (size_t
size);

2. calloc() This function is also like


This header malloc () function. But calloc
defines several () initializes the allocated
general-purpose memory to zero. But, malloc()
functions, doesn’t.
including Syntax: ptr = (cast_type *)
dynamic memory calloc (n, size);
C Library -
management,
<stdlib.h>
random number 3. realloc() This function modifies the
generation, allocated memory size by
stdlib.h
communication malloc () and calloc ()
with the functions to new size.
environment, Syntax: ptr = realloc
integer arithmetic, (ptr,newsize);
searching, sorting
and converting. 4. abort() It terminates the C program.
Syntax: <ABEND |
RETURN> <n>;

5. exit() This function terminates the


program and does not return
any value.
Syntax: void exit (int status);
Republic of the Philippines
City of Olongapo
GORDON COLLEGE
Olongapo City Sports Complex, East Tapinac, Olongapo City
College of computer studies

1. clearerr() It clears the end-of-file and


error indicators for the given
stream.
Syntax: void clearerr(FILE
The header file *stream);
stdio.h stands for
Standard Input 2. fclose() It closes the stream. All
Output. It has the buffers are flushed.
information Syntax: int fclose(FILE
related to *stream);
C Library - input/output
<stdio.h> functions. Here is 3. feof() It tests the end-of-file
the table that indicator for the given stream.
stdio.h displays some of Syntax: int feof(FILE
the functions in *stream);
stdio.h in C
language, It is 4. ferror() It tests the error indicator for
used to print the the given stream.
strings, integer, Syntax: int ferror(FILE
character etc on *stream);
the output screen.
5. fflush() It flushes the output buffer of
a stream.
Syntax: int fflush(FILE
*stream);
Republic of the Philippines
City of Olongapo
GORDON COLLEGE
Olongapo City Sports Complex, East Tapinac, Olongapo City
College of computer studies

1. memchr() It searches for the first


occurrence of the character c
(an unsigned char) in the first
n bytes of the string pointed
to, by the argument str.
Syntax: void *memchr(const
void *str, int c, size_t n);

2. memcmp() It compares the first n bytes


of memory area str1 and
String.h is one of memory area str2.
the header files Syntax: int memcmp (const
available in the void *s1, const void *s2,
C/C++ size_t n);
programming
C Library - language. string.h
<string.h> header file 3. memcpy() It copies n characters from
defines one memory area src to memory
string.h variable type, one area dest.
macro, and many Syntax: void *memcpy(void
functions which *dest, const void *src, size_t
can be used to n);
manipulate a
string or array of 4. memmove() It copies n characters from
characters. str2 to str1, but for
overlapping memory blocks,
memmove() is a safer
approach than memcpy().
Syntax: void
*memmove(void *str1, const
void *str2, size_t n);

5. memset() It copies the character c (an


unsigned char) to the first n
characters of the string
pointed to, by the argument
str.
Syntax: void *memset(void
*str, int c, size_t n);
Republic of the Philippines
City of Olongapo
GORDON COLLEGE
Olongapo City Sports Complex, East Tapinac, Olongapo City
College of computer studies

1. asctime() It returns a pointer to a string


which represents the day and
time of the structure struct
timeptr.
Syntax: char *asctime(const
struct tm *timeptr);

The time.h header 2. clock() It returns the number of clock


file contains ticks elapsed since the
definitions of program was launched. To
functions to get get the number of seconds
and manipulate used by the CPU, you will
C Library - date and time need to divide by
<time.h> information. It CLOCKS_PER_SEC.
describes three
time.h time-related data On a 32-bit system where
types. clock_t: CLOCKS_PER_SEC equals
clock_t represents 1000000 this function will
the date as an return the same value
integer which is a approximately every 72
part of the minutes.
calendar time. Syntax: clock_t clock(void);

3. ctime() It returns a string representing


the local time based on the
argument timer.
Syntax: char *ctime(const
time_t *timer);
Republic of the Philippines
City of Olongapo
GORDON COLLEGE
Olongapo City Sports Complex, East Tapinac, Olongapo City
College of computer studies

4. difftime() It returns the difference of


seconds between time1 and
time2 i.e. (time1 - time2).
The two times are specified in
calendar time, which
represents the time elapsed
since the Epoch (00:00:00 on
January 1, 1970, Coordinated
Universal Time (UTC)).
Syntax: double
difftime(time_t time1, time_t
time2);

5. gmtime() It uses the value pointed by


timer to fill a tm structure
with the values that represent
the corresponding time,
expressed in Coordinated
Universal Time (UTC) or
GMT timezone.
Syntax: struct tm
*gmtime(const time_t
*timer);

Add more rows if necessary

Source(s)/Reference(s):

1. C – stdlib.h library: C stdlib.h library functions | C Function | Fresh2Rfresh


(fresh2refresh.com)
2. C – stdio.h library: C Library - <stdio.h> (tutorialspoint.com)
3. C – string.h library: C Library - <string.h> (tutorialspoint.com)
4. C- time.h library: C Library - <time.h> (tutorialspoint.com)

You might also like