Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Errno. H in C

Explore Errno. H in C with clear explanations, practical examples, and useful tips.

Table of Contents

This guide covers errno. h in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.

Errno. H in C

Errno is set to 0 at the program start. The specific functions of the standard C library modify its value to a number greater than 0 to signal some type of error. You can also modify its value or restore it to 0 depending on your requirements.

The file header named errno. H also defines a list of macros to indicate different error codes.

The Macros Are Defined in Errno. H

The table below lists some macros defined in errno. H in Library C:

Macro Descriptionextern int errno

This is a macro set by system call and some library functions for errors to indicate that an error is occurring

EDOM Domain Error

This macro represents a domain error, which occurs if an input parameter is Outside the domain where the math function is defined And errno is set to EDOM.

ERANGE Range Loi

This macro represents a range error, which occurs if an input parameter is Outside the range of values for Which the function is defined, and errno is set to ERANGE.

1. Macro Errno in C

Macro Errno in C

The extern int errno macro in Library C is set by system call and some library functions for errors indicate that an error is occurring.

Declaring Errno Macro in C

Below is the declaration for errno macro in C.

 extern int errno 

Parameters

This macro does not receive any parameters

Returns the value

This macro does not return any values

For example

The following C program illustrates the usage of errno Macro in C.

 #include #include #include extern int errno ; int main () { FILE * fp ; fp = fopen ( "fileexample.txt" , "r" ); if ( fp == NULL ) { fprintf ( stderr , "Gia tri cua errno: %dn" , errno ); fprintf ( stderr , "Xay la loi khi mo file: %sn" , strerror ( errno )); } else { fclose ( fp ); } return ( 0 ); } 

Compile and run the above C program in case the file. Txt does not exist:

2. EDOM Macro in C

EDOM Macro in C

EDOM macros in Library C represent a domain error, which occurs if an input parameter is outside the domain where the math function is defined and errno is set to EDOM.

EDOM Macro Declaration in C

Below is the declaration for EDOM Macro in C.

 #define EDOM some_value 

Parameters

This macro does not receive any parameters

Returns the value

This macro does not return any values

For example

Program C follows the usage of EDOM Macro.

 #include #include #include int main () { double val ; errno = 0 ; val = sqrt (- 10 ); if ( errno == EDOM ) { printf ( "Gia tri khong hop le n" ); } else { printf ( "Gia tri hop len" ); } errno = 0 ; val = sqrt ( 10 ); if ( errno == EDOM ) { printf ( "Gia tri khong hop len" ); } else { printf ( "Gia tri hop len" ); } return ( 0 ); } 

Compiling and running the above C program will result:

3. Macro ERANGE in C

Macro ERANGE in C

The Macro ERANGE in Library C represents a range error, which occurs if an input parameter is outside the range of values for which the function is defined, and errno is set to ERANGE.

Declared Macro ERANGE in C

Below is the declaration for ERANGE Macro in C.

 #define ERANGE some_value 

Parameters

This macro does not receive any parameters

Returns the value

This macro does not return any values

For example

The following C program illustrates the use of ERANGE Macro.

 #include #include #include int main () { double x ; double value ; x = 2.000000 ; value = log ( x ); if ( errno == ERANGE ) { printf ( "Log(%f) la ben ngoai day gia tri cua ham logn" , x ); } else { printf ( "Log(%f) = %fn" , x , value ); } x = 1.000000 ; value = log ( x ); if ( errno == ERANGE ) { printf ( "Log(%f) la ben ngoai day gia tri cua ham logn" , x ); } else { printf ( "Log(%f) = %fn" , x , value ); } x = 0.000000 ; value = log ( x ); if ( errno == ERANGE ) { printf ( "Log(%f) la ben ngoai day gia tri cua ham logn" , x ); } else { printf ( "Log(%f) = %fn" , x , value ); } return 0 ; } 

Compiling and running the above C program will result:

According to Tutorialspoint

Last post: ctype. H in C

Next lesson: float. H in C

FAQ

What should I check before following these steps?

Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.

Why might the process not work?

Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.

Can I undo the changes if necessary?

That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.