Hex color | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

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 .

15th Jun 2020, 6:50 PM
Maryam K
Maryam K - avatar
1 Answer
+ 2
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👌..
15th Jun 2020, 8:32 PM
Amine Laaboudi
Amine Laaboudi - avatar