C 使用isdigit()宏分析命令行
我有以下代码从命令行读取参数。如果字符串的格式为hw:1,0,我想打断它C 使用isdigit()宏分析命令行,c,macros,C,Macros,我有以下代码从命令行读取参数。如果字符串的格式为hw:1,0,我想打断它 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] == ',' && isdig
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;
编译器给了我一个警告:
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])) {
^
还有一个问题:
将g#u strdup与GOptionContext结合使用是正确的您需要
#include
才能使用此函数/宏。当遇到隐式声明警告时
尝试寻找合适的include。我认为isdigit()
是ctype.h
as@nishant中的函数“它们可以实现为宏”,就像它们通常一样。