Here is the code:
#include <stdio.h> #include <stdbool.h> #include <ctype.h> bool isHex(char * str[20]){ return isxdigit(str); } int main(){ printf("%d\n", isHex("A8")); return 0; } I get the following message when I try to compile:
ishex.c:6:21: warning: incompatible pointer to integer conversion passing 'char **' to parameter of type 'int' [-Wint-conversion] return isxdigit(str); ^~~ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_ctype.h:280:14: note: passing argument to parameter '_c' here isxdigit(int _c) ^ ishex.c:13:26: warning: incompatible pointer types passing 'char [3]' to parameter of type 'char **' [-Wincompatible-pointer-types] printf("%d\n", isHex("A8")); ^~~~ ishex.c:5:19: note: passing argument to parameter 'str' here bool isHex(char * str[20]){
What is the issue in my code? I just want it to return true (1) if the string is a valid hex character, and false (0) if the string is not a valid hex character.
https://stackoverflow.com/questions/65947308/why-cant-my-function-take-in-a-char-variable-type January 29, 2021 at 08:49AM
没有评论:
发表评论