Library Functions in C
stdio.h Functions
printf
Description: Used to print output to the console.
Example: printf("Hello, World!\n");
scanf
Description: Used to take input from the user.
Example: scanf("%d", &x);
getchar
Description: Reads a single character from the standard input.
Example: char c = getchar();
putchar
Description: Outputs a single character to the standard output.
Example: putchar(c);
stdlib.h Functions
malloc
Description: Allocates memory dynamically.
Example: int *arr = (int *)malloc(5 * sizeof(int));
free
Description: Frees dynamically allocated memory.
Example: free(arr);
exit
Description: Terminates the program.
Example: exit(0);
atoi
Description: Converts a string to an integer.
Example: int num = atoi("1234");
string.h Functions
strcpy
Description: Copies one string to another.
Example: strcpy(dest, source);
strlen
Description: Returns the length of a string.
Example: int length = strlen("Hello");
strcat
Description: Concatenates two strings.
Example: strcat(dest, source);
strcmp
Description: Compares two strings.
Example: int result = strcmp(str1, str2);
math.h Functions
sqrt
Description: Returns the square root of a number.
Example: double result = sqrt(16);
pow
Description: Returns the value of x raised to the power of y.
Example: double result = pow(2, 3);
abs
Description: Returns the absolute value of a number.
Example: int result = abs(-5);
sin
Description: Returns the sine of an angle in radians.
Example: double result = sin(3.14);
time.h Functions
time
Description: Returns the current time.
Example: time_t t = time(NULL);
localtime
Description: Converts time_t to tm structure.
Example: struct tm *tm_info = localtime(&t);
strftime
Description: Formats the time in a specific format.
Example: strftime(buffer, 80, "%Y-%m-%d", tm_info);