Hex color | SoloLearn: Learn to code for FREE!


Hex color

Does anyone know how to check if a string is a valid hex color representation? I could find the codes is JS and other languages but i want it in c++ or c .

6/15/2020 6:50:41 PM

Maryam K

1 Answer

New Answer


Hi🙋Maryam ... For ex:: int check_hex(char str[]){ int i=0; char ch=str[i]; while(ch!='\0'){ if(!(isxdigit(ch)) return 0; i++; ch=str[i]; } return 1; } "isxdigit" function in C checkes that whether the given character is hexadecimal or not. And it's defined in ctype.h header file👌..