C Library –

C Library – <assert.h> ”; Previous Next The assert.h header file of the C Standard Library provides a macro called assert which can be used to verify assumptions made by the program and print a diagnostic message if this assumption is false. The defined macro assert refers to another macro NDEBUG which is not a part of <assert.h>. If NDEBUG is defined as a macro name in the source file, at the point where <assert.h> is included, the assert macro is defined as follows − #define assert(ignore) ((void)0) Library Macros Following is the only function defined in the header assert.h − Sr.No. Function & Description 1 void assert(int expression) This is actually a macro and not a function, which can be used to add diagnostics in your C program. 2 static_assert(boolean_expression, message) This macro issues a compile-time diagnostic if the value of a constant expression is false. Print Page Previous Next Advertisements ”;

C Library –

C Library – <limits.h> ”; Previous Next The C Library limits.h header file defines various properties of the different variable types. The macros defined in this header, limits the values of various variable types like char, int and long. These limits specify that a variable cannot store any value beyond these limits, for example an unsigned character can store up to a maximum value of 255. <limits.h> Library Macros The following values are implementation-specific and defined using the #define directive. However, these values may not be lower than the given ones. Macro Value Description CHAR_BIT 8 Defines the number of bits in a byte. SCHAR_MIN -128 Defines the minimum value for a signed char. SCHAR_MAX +127 Defines the maximum value for a signed char. UCHAR_MAX 255 Defines the maximum value for an unsigned char. CHAR_MIN -128 Defines the minimum value for type char and its value will be equal to SCHAR_MIN if char represents negative values, otherwise zero. CHAR_MAX +127 Defines the value for type char and its value will be equal to SCHAR_MAX if char represents negative values, otherwise UCHAR_MAX. MB_LEN_MAX 16 Defines the maximum number of bytes in a multi-byte character. SHRT_MIN -32768 Defines the minimum value for a short int. SHRT_MAX +32767 Defines the maximum value for a short int. USHRT_MAX 65535 Defines the maximum value for an unsigned short int. INT_MIN -2147483648 Defines the minimum value for an int. INT_MAX +2147483647 Defines the maximum value for an int. UINT_MAX 4294967295 Defines the maximum value for an unsigned int. LONG_MIN -9223372036854775808 Defines the minimum value for a long int. LONG_MAX +9223372036854775807 Defines the maximum value for a long int. ULONG_MAX 18446744073709551615 Defines the maximum value for an unsigned long int. Note that, the above macros help developer to write efficient code that works consistently across different platforms and compilers. Example 1 Following is the basic C Library program to display the range value of various macros under the limits.h header file. #include <stdio.h> #include <limits.h> int main() { printf(“The value of CHAR_BIT: %dn”, CHAR_BIT); printf(“The value of SCHAR_MIN: %dn”, SCHAR_MIN); printf(“The value of SCHAR_MAX: %dn”, SCHAR_MAX); printf(“The value of UCHAR_MAX: %un”, UCHAR_MAX); printf(“The value of CHAR_MIN: %dn”, CHAR_MIN); printf(“The value of CHAR_MAX: %dn”, CHAR_MAX); printf(“The value of MB_LEN_MAX: %dn”, MB_LEN_MAX); printf(“The value of SHRT_MIN: %dn”, SHRT_MIN); printf(“The value of SHRT_MAX: %dn”, SHRT_MAX); printf(“The value of USHRT_MAX: %un”, USHRT_MAX); printf(“The value of INT_MIN: %dn”, INT_MIN); printf(“The value of INT_MAX: %dn”, INT_MAX); printf(“The value of UINT_MAX: %un”, UINT_MAX); printf(“The value of LONG_MIN: %ldn”, LONG_MIN); printf(“The value of LONG_MAX: %ldn”, LONG_MAX); printf(“The value of ULONG_MAX: %lun”, ULONG_MAX); return 0; } Output On execution of above code, we get the following result − The value of CHAR_BIT: 8 The value of SCHAR_MIN: -128 The value of SCHAR_MAX: 127 The value of UCHAR_MAX: 255 The value of CHAR_MIN: -128 The value of CHAR_MAX: 127 The value of MB_LEN_MAX: 16 The value of SHRT_MIN: -32768 The value of SHRT_MAX: 32767 The value of USHRT_MAX: 65535 The value of INT_MIN: -2147483648 The value of INT_MAX: 2147483647 The value of UINT_MAX: 4294967295 The value of LONG_MIN: -9223372036854775808 The value of LONG_MAX: 9223372036854775807 The value of ULONG_MAX: 18446744073709551615 Example 2 In this example, we illustrate the program for finding the minimum and maximum values. #include <stdio.h> #include <limits.h> int main() { int input[] = {89, 5, 21, 10, 45, 31, 98}; int n = sizeof(input) / sizeof(input[0]); // Initialization of macros int min_value = INT_MAX; int max_value = INT_MIN; // loop iteration for min and max value for (int i = 0; i < n; ++i) { if (input[i] < min_value) { min_value = input[i]; } if (input[i] > max_value) { max_value = input[i]; } } // Display the result printf(“Minimum value: %dn”, min_value); printf(“Maximum value: %dn”, max_value); return 0; } Output On execution of above code, we get the following result − Minimum value: 5 Maximum value: 98 Example 3 Below the program initializes limit macros(CHAR_MIN/MAX) to generate the minimum and maximum length of character from the given string. #include <stdio.h> #include <limits.h> #include <string.h> int main() { char* char_input[] = {“RUSSIA”, “UK”, “INDIA”, “NEWYORK”, “INDONESIA”, “DUBAI”}; int num_strings = sizeof(char_input) / sizeof(char_input[0]); // Initialization of CHAR macros int min_length = CHAR_MAX; int max_length = CHAR_MIN; for (int i = 0; i < num_strings; ++i) { int current_length = strlen(char_input[i]); if (current_length < min_length) { min_length = current_length; } if (current_length > max_length) { max_length = current_length; } } printf(“Minimum length of characters: %dn”, min_length); printf(“Maximum length of characters: %dn”, max_length); return 0; } Output The above code produces the following result − Minimum length of characters: 2 Maximum length of characters: 9 Print Page Previous Next Advertisements ”;

C Library –

C Library – <stdlib.h> ”; Previous Next The stdlib.h header defines four variable types, several macros, and various functions for performing general functions. Library Variables Following are the variable types defined in the header stdlib.h − Sr.No. Variable & Description 1 size_t This is the unsigned integral type and is the result of the sizeof keyword. 2 wchar_t This is an integer type of the size of a wide character constant. 3 div_t This is the structure returned by the div function. 4 ldiv_t This is the structure returned by the ldiv function. Library Macros Following are the macros defined in the header stdlib.h − Sr.No. Macro & Description 1 NULL This macro is the value of a null pointer constant. 2 EXIT_FAILURE This is the value for the exit function to return in case of failure. 3 EXIT_SUCCESS This is the value for the exit function to return in case of success. 4 RAND_MAX This macro is the maximum value returned by the rand function. 5 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. Library Functions Following are the functions defined in the header stlib.h − Sr.No. Function & Description 1 double atof(const char *str) Converts the string pointed to, by the argument str to a floating-point number (type double). 2 int atoi(const char *str) Converts the string pointed to, by the argument str to an integer (type int). 3 long int atol(const char *str) Converts the string pointed to, by the argument str to a long integer (type long int). 4 double strtod(const char *str, char **endptr) Converts the string pointed to, by the argument str to a floating-point number (type double). 5 long int strtol(const char *str, char **endptr, int base) Converts the string pointed to, by the argument str to a long integer (type long int). 6 unsigned long int strtoul(const char *str, char **endptr, int base) Converts the string pointed to, by the argument str to an unsigned long integer (type unsigned long int). 7 void *calloc(size_t nitems, size_t size) Allocates the requested memory and returns a pointer to it. 8 void free(void *ptr Deallocates the memory previously allocated by a call to calloc, malloc, or realloc. 9 void *malloc(size_t size) Allocates the requested memory and returns a pointer to it. 10 void *realloc(void *ptr, size_t size) Attempts to resize the memory block pointed to by ptr that was previously allocated with a call to malloc or calloc. 11 void abort(void) Causes an abnormal program termination. 12 int atexit(void (*func)(void)) Causes the specified function func to be called when the program terminates normally. 13 void exit(int status) Causes the program to terminate normally. 14 char *getenv(const char *name) Searches for the environment string pointed to by name and returns the associated value to the string. 15 int system(const char *string) The command specified by string is passed to the host environment to be executed by the command processor. 16 void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *)) Performs a binary search. 17 void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*)) Sorts an array. 18 int abs(int x) Returns the absolute value of x. 19 div_t div(int numer, int denom) Divides numer (numerator) by denom (denominator). 20 long int labs(long int x) Returns the absolute value of x. 21 ldiv_t ldiv(long int numer, long int denom) Divides numer (numerator) by denom (denominator). 22 int rand(void) Returns a pseudo-random number in the range of 0 to RAND_MAX. 23 void srand(unsigned int seed) This function seeds the random number generator used by the function rand. 24 int mblen(const char *str, size_t n) Returns the length of a multibyte character pointed to by the argument str. 25 size_t mbstowcs(schar_t *pwcs, const char *str, size_t n) Converts the string of multibyte characters pointed to by the argument str to the array pointed to by pwcs. 26 int mbtowc(whcar_t *pwc, const char *str, size_t n) Examines the multibyte character pointed to by the argument str. 27 size_t wcstombs(char *str, const wchar_t *pwcs, size_t n) Converts the codes stored in the array pwcs to multibyte characters and stores them in the string str. 28 int wctomb(char *str, wchar_t wchar) Examines the code which corresponds to a multibyte character given by the argument wchar. Print Page Previous Next Advertisements ”;

C Library –

C Library – <stdarg.h> ”; Previous Next The stdarg.h header defines a variable type va_list and three macros which can be used to get the arguments in a function when the number of arguments are not known i.e. variable number of arguments. A function of variable arguments is defined with the ellipsis (,…) at the end of the parameter list. Library Variables Following is the variable type defined in the header stdarg.h − Sr.No. Variable & Description 1 va_list This is a type suitable for holding information needed by the three macros va_start(), va_arg() and va_end(). Library Macros Following are the macros defined in the header stdarg.h − Sr.No. Macro & Description 1 void va_start(va_list ap, parmN) This macro enables access to variadic function arguments. 2 type va_arg(va_list ap, type) This macro retrieves the next argument in the parameter list of the function with type type. 3 void va_end(va_list ap) This macro allows to end traversal of the variadic function arguments. 4 void va_copy( va_list dest, va_list src ) This macro makes a copy of the variadic function arguments. Print Page Previous Next Advertisements ”;

C Library – Quick Guide

C Standard Library – Quick Guide ”; Previous Next C Library – <assert.h> The assert.h header file of the C Standard Library provides a macro called assert which can be used to verify assumptions made by the program and print a diagnostic message if this assumption is false. The defined macro assert refers to another macro NDEBUG which is not a part of <assert.h>. If NDEBUG is defined as a macro name in the source file, at the point where <assert.h> is included, the assert macro is defined as follows − #define assert(ignore) ((void)0) Library Macros Following is the only function defined in the header assert.h − Sr.No. Function & Description 1 void assert(int expression) This is actually a macro and not a function, which can be used to add diagnostics in your C program. C Library – <ctype.h> The ctype.h header file of the C Standard Library declares several functions that are useful for testing and mapping characters. All the functions accepts int as a parameter, whose value must be EOF or representable as an unsigned char. All the functions return non-zero (true) if the argument c satisfies the condition described, and zero(false) if not. Library Functions Following are the functions defined in the header ctype.h − Sr.No. Function & Description 1 int isalnum(int c) This function checks whether the passed character is alphanumeric. 2 int isalpha(int c) This function checks whether the passed character is alphabetic. 3 int iscntrl(int c) This function checks whether the passed character is control character. 4 int isdigit(int c) This function checks whether the passed character is decimal digit. 5 int isgraph(int c) This function checks whether the passed character has graphical representation using locale. 6 int islower(int c) This function checks whether the passed character is lowercase letter. 7 int isprint(int c) This function checks whether the passed character is printable. 8 int ispunct(int c) This function checks whether the passed character is a punctuation character. 9 int isspace(int c) This function checks whether the passed character is white-space. 10 int isupper(int c) This function checks whether the passed character is an uppercase letter. 11 int isxdigit(int c) This function checks whether the passed character is a hexadecimal digit. The library also contains two conversion functions that accepts and returns an “int”. Sr.No. Function & Description 1 int tolower(int c) This function converts uppercase letters to lowercase. 2 int toupper(int c) This function converts lowercase letters to uppercase. Character Classes Sr.No. Character Class & Description 1 Digits This is a set of whole numbers { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }. 2 Hexadecimal digits This is the set of { 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f }. 3 Lowercase letters This is a set of lowercase letters { a b c d e f g h i j k l m n o p q r s t u v w x y z }. 4 Uppercase letters This is a set of uppercase letters {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z }. 5 Letters This is a set of lowercase and uppercase letters. 6 Alphanumeric characters This is a set of Digits, Lowercase letters and Uppercase letters. 7 Punctuation characters This is a set of ! ” # $ % & ” ( ) * + , – . / : ; < = > ? @ [ ] ^ _ ` { | } ~ 8 Graphical characters This is a set of Alphanumeric characters and Punctuation characters. 9 Space characters This is a set of tab, newline, vertical tab, form feed, carriage return, and space. 10 Printable characters This is a set of Alphanumeric characters, Punctuation characters and Space characters. 11 Control characters In ASCII, these characters have octal codes 000 through 037, and 177 (DEL). 12 Blank characters These are spaces and tabs. 13 Alphabetic characters This is a set of Lowercase letters and Uppercase letters. C Library – <errno.h> The errno.h header file of the C Standard Library defines the integer variable errno, which is set by system calls and some library functions in the event of an error to indicate what went wrong. This macro expands to a modifiable lvalue of type int, therefore it can be both read and modified by a program. The errno is set to zero at program startup. Certain functions of the standard C library modify its value to other than zero to signal some types of error. You can also modify its value or reset to zero at your convenience. The errno.h header file also defines a list of macros indicating different error codes, which will expand to integer constant expressions with type int. Library Macros Following are the macros defined in the header errno.h − Sr.No. Macro & Description 1 extern int errno This is the macro set by system calls and some library functions in the event of an error to indicate what went wrong. 2 EDOM Domain Error This macro represents a domain error, which occurs if an input argument is outside the domain, over which the mathematical function is defined and errno is set to EDOM. 3 ERANGE Range Error This macro represents a range error, which occurs if an input argument is outside the range, over which the mathematical function is defined and errno is set to ERANGE. C Library – <float.h> The float.h header file of the C Standard Library contains a set of various platform-dependent constants related to floating point values. These constants are proposed by ANSI C. They allow making more portable programs. Before checking all the constants, it is good to understand that floating-point number is composed of following four elements − Sr.No. Component & Component Description 1 S sign ( +/- ) 2 b base or

C Library – Discussion

Discuss C Standard Library ”; Previous Next C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the Unix operating system. C is the most widely used computer language, that keeps fluctuating at number one scale of popularity along with Java programming language which is also equally popular and most widely used among modern software programmers. The C Standard Library is a set of C built-in functions, constants and header files like <stdio.h>, <stdlib.h>, <math.h>, etc. This library will work as a reference manual for C programmers. Print Page Previous Next Advertisements ”;

C Library – Useful Resources

C Standard Library – Useful Resources ”; Previous Next The following resources contain additional information on C Standard Library. Please use them to get more in-depth knowledge on this. Useful Video Courses STL – Standard Template Library in C++ : Data Structures 15 Lectures 1 hours Anant Rungta More Detail VMware vSphere 7: install, configure, manage [v7] VCTA 2021 Featured 109 Lectures 8 hours TAL Mohamed More Detail Indian Accounting Standards (Ind AS) Certificate Training 58 Lectures 41 hours Uplatz More Detail International Accounting Standards (AS) Certificate 2023 31 Lectures 18.5 hours Uplatz More Detail Candlestick Patterns & Analysis A-Z Masterclass 19 Lectures 1 hours Travis Rose More Detail Adobe After Effects Ultimate guide 2022 169 Lectures 6 hours Learn Tech Plus More Detail Print Page Previous Next Advertisements ”;

C – Useful Resources

C Programming – Useful Resources ”; Previous Next The following resources contain additional information on C Programming. Please use them to get more in-depth knowledge on this. Useful Video Courses Learn Parallel Programming with c# and .NET Core 5 Best Seller 23 Lectures 2.5 hours V.D More Detail Complete C++ Programming Fundamentals with Example Projects 160 Lectures 16.5 hours Emenwa Global, Ejike IfeanyiChukwu More Detail Complete C++ Programming Course With Example Project 196 Lectures 21.5 hours Emenwa Global, Ejike IfeanyiChukwu More Detail C Programming Course from Scratch – Beginners in Hindi/Urdu 20 Lectures 7.5 hours Subrat Kumar Das More Detail C++ Programming for Beginners 15 Lectures 10.5 hours Uplatz More Detail Embedded C Programming Course 14 Lectures 10 hours Uplatz More Detail Print Page Previous Next Advertisements ”;

C Library –

C Library – <locale.h> ”; Previous Next The locale.h header defines the location specific settings, such as date formats and currency symbols. You will find several macros defined along with an important structure struct lconv and two important functions listed below. Library Macros Following are the macros defined in the header and these macros will be used in two functions listed below − Sr.No. Macro & Description 1 LC_ALL Sets everything. 2 LC_COLLATE Affects strcoll and strxfrm functions. 3 LC_CTYPE Affects all character functions. 4 LC_MONETARY Affects the monetary information provided by localeconv function. 5 LC_NUMERIC Affects decimal-point formatting and the information provided by localeconv function. 6 LC_TIME Affects the strftime function. Library Functions Following are the functions defined in the header locale.h − Sr.No. Function & Description 1 char *setlocale(int category, const char *locale) Sets or reads location dependent information. 2 struct lconv *localeconv(void) Sets or reads location dependent information. Print Page Previous Next Advertisements ”;

C Library –

C Library – <string.h> ”; Previous Next The string.h header defines one variable type, one macro, and various functions for manipulating arrays of characters. Library Variables Following is the variable type defined in the header string.h − Sr.No. Variable & Description 1 size_t This is the unsigned integral type and is the result of the sizeof keyword. C Library string.h Macros Following is the macro defined in the header string.h − Sr.No. Macro & Description 1 NULL This macro is the value of a null pointer constant. C Library string.h Functions Following are the functions defined in the header string.h − Sr.No. Function & Description 1 void *memchr(const void *str, int c, size_t n) 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. 2 int memcmp(const void *str1, const void *str2, size_t n) Compares the first n bytes of str1 and str2. 3 void *memcpy(void *dest, const void *src, size_t n) Copies n characters from src to dest. 4 void *memmove(void *dest, const void *src, size_t n) Another function to copy n characters from str2 to str1. 5 void *memset(void *str, int c, size_t n) Copies the character c (an unsigned char) to the first n characters of the string pointed to, by the argument str. 6 char *strcat(char *dest, const char *src) Appends the string pointed to, by src to the end of the string pointed to by dest. 7 char *strncat(char *dest, const char *src, size_t n) Appends the string pointed to, by src to the end of the string pointed to, by dest up to n characters long. 8 char *strchr(const char *str, int c) Searches for the first occurrence of the character c (an unsigned char) in the string pointed to, by the argument str. 9 int strcmp(const char *str1, const char *str2) Compares the string pointed to, by str1 to the string pointed to by str2. 10 int strncmp(const char *str1, const char *str2, size_t n) Compares at most the first n bytes of str1 and str2. 11 int strcoll(const char *str1, const char *str2) Compares string str1 to str2. The result is dependent on the LC_COLLATE setting of the location. 12 char *strcpy(char *dest, const char *src) Copies the string pointed to, by src to dest. 13 char *strncpy(char *dest, const char *src, size_t n) Copies up to n characters from the string pointed to, by src to dest. 14 size_t strcspn(const char *str1, const char *str2) Calculates the length of the initial segment of str1 which consists entirely of characters not in str2. 15 char *strerror(int errnum) Searches an internal array for the error number errnum and returns a pointer to an error message string. 16 size_t strlen(const char *str) Computes the length of the string str up to but not including the terminating null character. 17 char *strpbrk(const char *str1, const char *str2) Finds the first character in the string str1 that matches any character specified in str2. 18 char *strrchr(const char *str, int c) Searches for the last occurrence of the character c (an unsigned char) in the string pointed to by the argument str. 19 size_t strspn(const char *str1, const char *str2) Calculates the length of the initial segment of str1 which consists entirely of characters in str2. 20 char *strstr(const char *haystack, const char *needle) Finds the first occurrence of the entire string needle (not including the terminating null character) which appears in the string haystack. 21 char *strtok(char *str, const char *delim) Breaks string str into a series of tokens separated by delim. 22 size_t strxfrm(char *dest, const char *src, size_t n) Transforms the first n characters of the string src into current locale and places them in the string dest. Print Page Previous Next Advertisements ”;