strtol 함수를 이용하면 된다.
int main(void)
{
char abc[] = "#ff9911";
char a[2];
char b[2];
char c[2];
strncpy(a, abc + 1, 2);
strncpy(b, abc + 3, 2);
strncpy(c, abc + 5, 2);
long a1 = strtol(a, NULL, 16);
long b1 = strtol(b, NULL, 16);
long c1 = strtol(c, NULL, 16);
return 0;
}
{
char abc[] = "#ff9911";
char a[2];
char b[2];
char c[2];
strncpy(a, abc + 1, 2);
strncpy(b, abc + 3, 2);
strncpy(c, abc + 5, 2);
long a1 = strtol(a, NULL, 16);
long b1 = strtol(b, NULL, 16);
long c1 = strtol(c, NULL, 16);
return 0;
}
'C/C++' 카테고리의 다른 글
[C/C++] Effective C++ (0) | 2009.09.28 |
---|---|
[Socket]Unix Socket 프로그래밍 방법들 (0) | 2008.07.23 |
[기본]변수 키워드 (0) | 2008.07.14 |
[Socket] Option (0) | 2008.07.08 |
Big Endian , Little Endian (0) | 2008.07.05 |