Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7809469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:26:49+00:00 2026-06-02T03:26:49+00:00

I have the following code to read an argument from the command line. If

  • 0

I have the following code to read an argument from the command line. If the string is 1 character long and a digit I want to use that as the exit value. The compiler gives me a warning on the second line (array subscript has type ‘char’ ) This error comes from the second part after the “&&” .

    if (args[1] != NULL) {
        if ((strlen(args[1]) == 1) && isdigit(*args[1]))
            exit(((int) args[1][0]));
        else
            exit(0);
    }
}

Also, when I use a different compiler I get two errors on the next line (exit).

builtin.c: In function 'builtin_command':
builtin.c:55: warning: implicit declaration of function 'exit'
builtin.c:55: warning: incompatible implicit declaration of built-in function 'exit'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:26:51+00:00Added an answer on June 2, 2026 at 3:26 am

    The trouble is that the isdigit() macro takes an argument which is an integer that is either the value EOF or the value of an unsigned char.

    ISO/IEC 9899:1999 (C Standard – old), §7.4 Character handling <ctype.h>, ¶1:

    In all cases the argument is an int, the value of which shall be
    representable as an unsigned char or shall equal the value of the macro EOF. If the
    argument has any other value, the behavior is undefined.

    On your platform, char is signed, so if you have a character in the range 0x80..0xFF, it will be treated as a negative integer. The usual implementation of the isdigit() macros is to use the argument to index into an array of flag bits. Therefore, if you pass a char from the range 0x80..0xFF, you will be indexing before the start of the array, leading to undefined behaviour.

    #define isdigit(x)  (_CharType[(x)+1]&_Digit)
    

    You can safely use isdigit() in either of two ways:

    int c = getchar();
    
    if (isdigit(c))
        ...
    

    or:

    if (isdigit((unsigned char)*args[1]))
        ...
    

    In the latter case, you know that the value won’t be EOF. Note that this is not OK:

    int c = *args[1];
    
    if (isdigit(c))  // Undefined behaviour if *args[1] in range 0x80..0xFF
        ...
    

    The warning about ‘implicit definition of function exit’ means you did not include <stdlib.h> but you should have done so.

    You might also notice that if the user gives you a 2 as the first character of the first argument, the exit status will be 50, not 2, because '2' is (normally, in ASCII and UTF-8 and 8859-1, etc) character code 50 ('0' is 48, etc). You’d get 2 (no quotes) by using *args[1] - '0' as the argument to exit(). You don’t need a cast on that expression, though it won’t do much harm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function from some legacy code that I am maintaining. long
I read from a book saying that the following c++ code should not compile:
I'm using boost::program_options to read the users' input from the command line argument. It
When I using the following code to read file: lines=file(data.txt).read().split(\n) I have the following
I have the following code: $SQL = UPDATE jobs SET read = '1' WHERE
I have the following code: f = open(path, 'r') html = f.read() # no
i have the following code: <p class=more><a href=/stories class=more>Read more</a></p> and CSS: a.more, a.back
Have a look at the following code you are not required to read the
I have the following code which i copied from here : /*************************************************************************** * _
I have some code that has to compile for multiple platforms. The following will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.