0% found this document useful (0 votes)
8 views

Common Library Functions in C

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Common Library Functions in C

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In C programming, leveraging library functions is essential for building efficient and versatile

programs. These pre-defined functions, grouped in header files, provide a rich set of
functionalities to perform various tasks without reinventing the wheel. Here's a breakdown of
some commonly used library functions in C:

1. Mathematical Functions (math.h header):

● Trigonometric Functions:
○ sin(x): Sine of angle x (in radians).
○ cos(x): Cosine of angle x (in radians).
○ tan(x): Tangent of angle x (in radians).
○ asin(x): Arcsine (inverse sine) of x.
○ acos(x): Arccosine (inverse cosine) of x.
○ atan(x): Arctangent (inverse tangent) of x.
● Exponential and Logarithmic Functions:
○ exp(x): Raises e (Euler's number) to the power of x.
○ log(x): Natural logarithm (base-e) of x.
○ log10(x): Base-10 logarithm of x.
● Power Function:
○ pow(x, y): Raises x to the power of y.
● Rounding and Absolute Value Functions:
○ ceil(x): Returns the smallest integer greater than or equal to x.
○ floor(x): Returns the largest integer less than or equal to x.
○ round(x): Rounds x to the nearest integer.
○ abs(x): Returns the absolute value (non-negative) of x.
● Square Root:
○ sqrt(x): Square root of x.
● Other Functions:
○ fmod(x, y): Remainder of floating-point division x / y.
○ remainder(x, y): Integer remainder of division x / y.

2. Input/Output (I/O) Operations (stdio.h header):

● Formatted Input/Output:
○ printf(format, ...): Prints formatted output to the console or a file. The format string
specifies placeholders for arguments (...) that are inserted during printing.
○ scanf(format, ...): Reads formatted input from the console or a file. The format string
specifies the expected format of input, and arguments (...) store the read values.
● Character I/O:
○ getchar(): Reads a single character from the console.
○ putchar(c): Writes a single character c to the console.
● File I/O:
○ fopen(filename, mode): Opens a file named filename in the specified mode (e.g., "r" for
reading, "w" for writing). Returns a file pointer if successful.
○ fclose(fp): Closes the file pointed to by fp.
○ fscanf(fp, format, ...): Reads formatted data from a file pointed to by fp.
○ fprintf(fp, format, ...): Writes formatted data to a file pointed to by fp.
3. String Manipulation (string.h header):

● strlen(str): Returns the length (number of characters) of the string str (excluding the null
terminator).
● strcpy(dest, src): Copies the string src (including the null terminator) to dest. (Caution:
potential buffer overflow if dest is too small)
● strcat(dest, src): Appends the string src to the end of dest. (Caution: potential buffer overflow)
● strcmp(str1, str2): Compares strings str1 and str2. Returns 0 if equal, negative if str1 is less
than str2, positive if str1 is greater than str2.
● strstr(haystack, needle): Searches for the first occurrence of the string needle within
haystack. Returns a pointer to the beginning of the substring if found, or NULL if not found.
● Additional String Functions:
○ strncpy(dest, src, num): Copies at most num characters from src to dest, padding with null
characters if src is shorter.
○ `strn

You might also like