user1840007
user1840007

Reputation: 675

use isdigit() macro to parse command line

I have the following code to read an argument from the command line. If the string is in this form hw:1,0 I want to break.

gboolean parse_one_option (gint opt, const gchar * arg, GError ** err)
{
    switch (opt) {
    case DEVICE:
        if (!strncmp(arg, "hw:", 3) && isdigit(arg[3]) && arg[4] == ',' && isdigit(arg[5])) {
            char *device = g_strdup (arg);
            break;
        break;

The compiler gives me a warning:

warning: implicit declaration of function 'isdigit' is invalid in C99 [-Wimplicit-function-declaration]
                    if (!strncmp(arg, "hw:", 3) && isdigit(arg[3]) && arg[4] == ',' && isdigit(arg[5])) {
                                                   ^

and another question:

Is correct to use g_strdup in combination with GOptionContext

Upvotes: 0

Views: 5717

Answers (1)

user529758
user529758

Reputation:

You need to #include <ctype.h> for this function/macro to be available.

Upvotes: 9

Related Questions