How to check if a number in string is hexadecimal number (base 16) in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

int main()
{
    char s1[32] = "31FC";
    
    if (s1[strspn(s1, "0123456789abcdefABCDEF")] == 0) {
        printf("yes\n");
    }
    else {
        printf("no\n");
    }
	
	
	char s2[32] = "1D20K";
    if (s2[strspn(s2, "0123456789abcdefABCDEF")] == 0) {
        printf("yes\n");
    }
    else {
        printf("no\n");
    }
	
    return 0;
}
         
           
           
           
/*
run:
           
yes
no
        
*/

 



answered Jul 13, 2020 by avibootz

Related questions

1 answer 233 views
1 answer 269 views
269 views asked May 17, 2014 by avibootz
1 answer 176 views
2 answers 307 views
2 answers 268 views
...