How to convert hex to RGB struct in C++

1 Answer

0 votes
#include <iostream>

typedef struct RGBs {
    int r, g, b;
} RGB;

int main(void) {
    char const *hex = "fa9805";
    RGB rgbColor;
      
    sscanf(hex, "%02x%02x%02x", &rgbColor.r, &rgbColor.g, &rgbColor.b);

    std::cout << rgbColor.r << " " << rgbColor.g << " " << rgbColor.b;
      
    return 0;
}
  
  
  
  
/*
run:
  
250 152 5
  
*/

 



answered Dec 30, 2021 by avibootz

Related questions

1 answer 202 views
202 views asked Dec 29, 2021 by avibootz
1 answer 156 views
156 views asked Dec 30, 2021 by avibootz
1 answer 178 views
178 views asked Dec 29, 2021 by avibootz
2 answers 224 views
1 answer 154 views
154 views asked Dec 29, 2021 by avibootz
2 answers 202 views
202 views asked Dec 29, 2021 by avibootz
...