C Library –

C library – <inttypes.h> ”; Previous Next The C library header <inttypes.h> provides various macros for formatting and working with numeric data type(int). These macros are useful when we are using printf() and scanf() function. Library Macros Here, we are going to explore some important key macros of inttypes.h − Macros of output format specifier − printf() function PRIxMAX: This is printf specifier for intmax_t which is equivalent to %x(hexadecimal). PRIiMAX: This is printf specifier for intmax_t which is equivalent to %i(integer). PRIuLEAST32: This is printf specifier for uint_least32_t which is equivalent to %u(unsigned). Macros of input format specifier − scanf() function Similar to printf() function, here are some macros which is used for reading input− SCNxMAX: This is scanf specifier for intmax_t which is equivalent to %x(hexadecimal). SCNiMAX: This is scanf specifier for intmax_t which is equivalent to %i(integer). SCNuLEAST32: This is scanf specifier for uint_least32_t which is equivalent to %u(unsigned). String function Macros Below are list of some macros which supports string function − strtoimax(str, endptr, base): It is equivalent to strtol() for intmax_t. strtoumax(str, endptr, base): It is equivalent to strtoul() for uintmax_t. wcstoimax(wcs, endptr, base): It is equivalent to wcstol() for intmax_t. wcstoumax(wcs, endptr, base): It is equivalent to wcstoul() for uintmax_t. Example 1 Following is C library header <inttypes.h> which provide the program for printing integer value with a fixed width. #include <stdio.h> #include <inttypes.h> int main() { int32_t num1 = 67543; int64_t num2 = 894432590; printf(“Formatted output using inttypes.h:n”); printf(“num1: %” PRId32 “n”, num1); printf(“num2: %” PRId64 “n”, num2); return 0; } Output On execution of above code, we get the following result − Formatted output using inttypes.h: num1: 67543 num2: 894432590 Example 2 Below the program calculate the factorial of a number using unintmax_t under the header inttypes.h. #include <stdio.h> #include <inttypes.h> uintmax_t factorial(uintmax_t n) { if (n == 0) return 1; else return n * factorial(n – 1); } int main() { uintmax_t num = 5; printf(“Factorial of %” PRIuMAX ” = %” PRIuMAX “n”, num, factorial(num)); return 0; } Output After executing the code, we get the following result − Factorial of 5 = 120 Example 3 Below the program reads a 64-bit unsigned integer from the user using SCNu64. It then prints the entered value using PRIu64. #include <stdio.h> #include <inttypes.h> int main() { uint64_t large_number = 9876543210; printf(“The entered number: %” PRIu64 “n”, large_number); return 0; } Output The above code produces the following result − The entered number: 9876543210 Print Page Previous Next Advertisements ”;

C Library –

C library – <stdbool.h> ”; Previous Next The C library <stdbool.h> header supports the bool data types. The bool can store the value as true(0) or false(1) which is common requirement in various programming languages. There are three ways to perform the implementation of this header − The stdbool.h − This is C header which support the boolean variable. The Enumeration (enum) type − This is special type of data which is defined by the user. This includes either integral constant or integer. Declare the boolean values − The value can be defined as true or false. Example 1 Following is the simple C library header <stdbool> to see the conversion of boolean value in integer form. #include <stdbool.h> #include <stdio.h> int main() { // Declaration of boolean data types bool x = true; bool y = false; printf(“True : %dn”, x); printf(“False : %d”, y); return 0; } Output The above code produces the following output − True : 1 False : 0 Example 2 Below the program create an enumeration(enum) type to represent boolean values explicitly. #include <stdio.h> enum Bool { FALSE, TRUE }; int main() { enum Bool isTrue = TRUE; enum Bool isFalse = FALSE; // Rest of your code… printf(“isTrue: %dn”, isTrue); printf(“isFalse: %dn”, isFalse); // Rest of your program logic… return 0; } Output The above code produces the following output − isTrue: 1 isFalse: 0 Example 3 Here, we directly declare the boolean value using integer constants which shows the 0 for false and 1 for true. #include <stdio.h> int main() { int isTrue = 1; // true int isFalse = 0; // false printf(“isTrue: %dn”, isTrue); printf(“isFalse: %dn”, isFalse); return 0; } Output The above code produces the following output − isTrue: 1 isFalse: 0 Print Page Previous Next Advertisements ”;

C Library –

C Library – <signal.h> ”; Previous Next The signal.h header defines a variable type sig_atomic_t, two function calls, and several macros to handle different signals reported during a program”s execution. Library Variables Following is the variable type defined in the header signal.h − Sr.No. Variable & Description 1 sig_atomic_t This is of int type and is used as a variable in a signal handler. This is an integral type of an object that can be accessed as an atomic entity, even in the presence of asynchronous signals. Library Macros Following are the macros defined in the header signal.h and these macros will be used in two functions listed below. The SIG_ macros are used with the signal function to define signal functions. Sr.No. Macro & Description 1 SIG_DFL Default signal handler. 2 SIG_ERR Represents a signal error. 3 SIG_IGN Signal ignore. The SIG macros are used to represent a signal number in the following conditions − Sr.No. Macro & Description 1 SIGABRT Abnormal program termination. 2 SIGFPE Floating-point error like division by zero. 3 SIGILL Illegal operation. 4 SIGINT Interrupt signal such as ctrl-C. 5 SIGSEGV Invalid access to storage like segment violation. 6 SIGTERM Termination request. Library Functions Following are the functions defined in the header signal.h − Sr.No. Function & Description 1 void (*signal(int sig, void (*func)(int)))(int) This function sets a function to handle signal i.e. a signal handler. 2 int raise(int sig) This function causes signal sig to be generated. The sig argument is compatible with the SIG macros. Print Page Previous Next Advertisements ”;

C Library –

C Library – <stdio.h> ”; Previous Next The stdio.h header defines three variable types, several macros, and various functions for performing input and output. Library Variables Following are the variable types defined in the header stdio.h − Sr.No. Variable & Description 1 size_t This is the unsigned integral type and is the result of the sizeof keyword. 2 FILE This is an object type suitable for storing information for a file stream. 3 fpos_t This is an object type suitable for storing any position in a file. Library Macros Following are the macros defined in the header stdio.h − Sr.No. Macro & Description 1 NULL This macro is the value of a null pointer constant. 2 _IOFBF, _IOLBF and _IONBF These are the macros which expand to integral constant expressions with distinct values and suitable for the use as third argument to the setvbuf function. 3 BUFSIZ This macro is an integer, which represents the size of the buffer used by the setbuf function. 4 EOF This macro is a negative integer, which indicates that the end-of-file has been reached. 5 FOPEN_MAX This macro is an integer, which represents the maximum number of files that the system can guarantee to be opened simultaneously. 6 FILENAME_MAX This macro is an integer, which represents the longest length of a char array suitable for holding the longest possible filename. If the implementation imposes no limit, then this value should be the recommended maximum value. 7 L_tmpnam This macro is an integer, which represents the longest length of a char array suitable for holding the longest possible temporary filename created by the tmpnam function. 8 SEEK_CUR, SEEK_END, and SEEK_SET These macros are used in the fseek function to locate different positions in a file. 9 TMP_MAX This macro is the maximum number of unique filenames that the function tmpnam can generate. 10 stderr, stdin, and stdout These macros are pointers to FILE types which correspond to the standard error, standard input, and standard output streams. Library Functions Following are the functions defined in the header stdio.h − Sr.No. Function & Description 1 int fclose(FILE *stream) Closes the stream. All buffers are flushed. 2 void clearerr(FILE *stream) Clears the end-of-file and error indicators for the given stream. 3 int feof(FILE *stream) Tests the end-of-file indicator for the given stream. 4 int ferror(FILE *stream) Tests the error indicator for the given stream. 5 int fflush(FILE *stream) Flushes the output buffer of a stream. 6 int fgetpos(FILE *stream, fpos_t *pos) Gets the current file position of the stream and writes it to pos. 7 FILE *fopen(const char *filename, const char *mode) Opens the filename pointed to by filename using the given mode. 8 size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) Reads data from the given stream into the array pointed to by ptr. 9 FILE *freopen(const char *filename, const char *mode, FILE *stream) Associates a new filename with the given open stream and same time closing the old file in stream. 10 int fseek(FILE *stream, long int offset, int whence) Sets the file position of the stream to the given offset. The argument offset signifies the number of bytes to seek from the given whence position. 11 int fsetpos(FILE *stream, const fpos_t *pos) Sets the file position of the given stream to the given position. The argument pos is a position given by the function fgetpos. 12 long int ftell(FILE *stream) Returns the current file position of the given stream. 13 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) Writes data from the array pointed to by ptr to the given stream. 14 int remove(const char *filename) Deletes the given filename so that it is no longer accessible. 15 int rename(const char *old_filename, const char *new_filename) Causes the filename referred to, by old_filename to be changed to new_filename. 16 void rewind(FILE *stream) Sets the file position to the beginning of the file of the given stream. 17 void setbuf(FILE *stream, char *buffer) Defines how a stream should be buffered. 18 int setvbuf(FILE *stream, char *buffer, int mode, size_t size) Another function to define how a stream should be buffered. 19 FILE *tmpfile(void) Creates a temporary file in binary update mode (wb+). 20 char *tmpnam(char *str) Generates and returns a valid temporary filename which does not exist. 21 int fprintf(FILE *stream, const char *format, …) Sends formatted output to a stream. 22 int printf(const char *format, …) Sends formatted output to stdout. 23 int sprintf(char *str, const char *format, …) Sends formatted output to a string. 24 int vfprintf(FILE *stream, const char *format, va_list arg) Sends formatted output to a stream using an argument list. 25 int vprintf(const char *format, va_list arg) Sends formatted output to stdout using an argument list. 26 int vsprintf(char *str, const char *format, va_list arg) Sends formatted output to a string using an argument list. 27 int fscanf(FILE *stream, const char *format, …) Reads formatted input from a stream. 28 int scanf(const char *format, …) Reads formatted input from stdin. 29 int sscanf(const char *str, const char *format, …) Reads formatted input from a string. 30 int fgetc(FILE *stream) Gets the next character (an unsigned char) from the specified stream and advances the position indicator for the stream. 31 char *fgets(char *str, int n, FILE *stream) Reads a line from the specified stream and stores it into the string pointed to by str. It stops when either (n-1) characters are read, the newline character is read, or the end-of-file is reached, whichever comes first. 32 int fputc(int char, FILE *stream) Writes a character (an unsigned char) specified by the argument char to the specified stream and advances the position indicator for the stream. 33 int fputs(const char *str, FILE *stream) Writes a string to the specified stream up to but not including the null character. 34 int getc(FILE *stream) Gets the next character (an unsigned char) from the specified stream and advances the position indicator for the stream. 35 int getchar(void) Gets a character (an

C Library –

C Library – <errno.h> ”; Previous Next 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. 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 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 ”;