Is errnum an external variable like errno?

This is a discussion on Is errnum an external variable like errno? within the C++ Programming forums, part of the General Programming Boards category; The strerror library function definition is : char *strerror (int errnum) It will map the integer errnum argument (which can ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    8

    Is errnum an external variable like errno?

    The strerror library function definition is :

    char *strerror (int errnum)

    It will map the integer errnum argument (which can be the errno value) to an error rmessage and return a pointer to the message.

    I don't know how to use errnum, I tried to use it an external variable like errno, but doesn't work.

    In the following script,

    if (!(df = fopen(data_file, "r")))
    {
    fprintf(stderr, "(%s) Cannot open %s: %s\n", argv[0], data_file, strerror(errnum));
    exit(1);
    }

    I got the error message, it shows :
    'errnum' : undeclared identifier

    Who can give me any idea? Thanks.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    You need to use errno itself. errno is set on an error in a system-level call. Because errno holds the value for the last call that set it, this value may be changed by succeeding calls. Always check errno immediately before and after a call that may set it.

    Code:
    fprintf(stderr, "(%s) Cannot open %s: %s\n", argv[0], data_file, strerror(errnum)); 
    
    to
    
    fprintf(stderr, "(%s) Cannot open %s: %s\n", argv[0], data_file, strerror( errno ));

  3. #3
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    On my system errno isn't a variable but a #defined
    function call.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  3. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 04:31 PM
  4. Need help
    By awkeller in forum C Programming
    Replies: 2
    Last Post: 12-09-2001, 03:02 PM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21