Using strerror()/strerror_s() C functions to print the error messages

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows 2003 Server Standard Edition

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info:

To do: Printing error strings for the respective error numbers using strerror()/strerror_s() C function

To show: Using the strerror()/strerror_s() C function to display the error messages for the respective error numbers

 

 

// Using strerror()

#include <stdio.h>

#include <string.h>

 

int main(void)

{

// For the error number

int i;

// Reserve a buffer to store the error string

char buff[256];

 

printf("strerror()/strerror_s() - string errors\n");

printf("---------------------------------------\n");

 

// Loop for the error number from 1 to 40

for(i = 1; i < 40; i++)

{

printf("errnum = %d --> ", i);

// strerror(1) - using a secure version

strerror_s(buff, 100, i);

// print the respective error strings...

fprintf(stderr, buff);

printf("\n");

}

return 0;

}

 

Output example:

 

strerror()/strerror_s() - string errors

---------------------------------------

errnum = 1 --> Operation not permitted

errnum = 2 --> No such file or directory

errnum = 3 --> No such process

errnum = 4 --> Interrupted function call

errnum = 5 --> Input/output error

errnum = 6 --> No such device or address

errnum = 7 --> Arg list too long

errnum = 8 --> Exec format error

errnum = 9 --> Bad file descriptor

errnum = 10 --> No child processes

errnum = 11 --> Resource temporarily unavailable

errnum = 12 --> Not enough space

errnum = 13 --> Permission denied

errnum = 14 --> Bad address

errnum = 15 --> Unknown error

errnum = 16 --> Resource device

errnum = 17 --> File exists

errnum = 18 --> Improper link

errnum = 19 --> No such device

errnum = 20 --> Not a directory

errnum = 21 --> Is a directory

errnum = 22 --> Invalid argument

errnum = 23 --> Too many open files in system

errnum = 24 --> Too many open files

errnum = 25 --> Inappropriate I/O control operation

errnum = 26 --> Unknown error

errnum = 27 --> File too large

errnum = 28 --> No space left on device

errnum = 29 --> Invalid seek

errnum = 30 --> Read-only file system

errnum = 31 --> Too many links

errnum = 32 --> Broken pipe

errnum = 33 --> Domain error

errnum = 34 --> Result too large

errnum = 35 --> Unknown error

errnum = 36 --> Resource deadlock avoided

errnum = 37 --> Unknown error

errnum = 38 --> Filename too long

errnum = 39 --> No locks available

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index