Error, can't find whats wrong

I can't find what is wrong with my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
...
typedef struct
{
    unsigned char r;
    unsigned char g;
    unsigned char b;
}COLOR;
COLOR my_color = { 255, 255, 255 }; //default white
...
char* str_find_digit(char* beg, char* end)
{
	if(beg < end)
	{
		for( ;beg != end; ++beg)
		{
			if(isdigit(*beg))
				return beg;
		}
	}
	return end;
}
...
// test input string, i will do this from file later
char buffer[] = " 1#- ,23@";
size_t buffer_sz = strlen(buffer);

unsigned long tmp_color[3];

char* begin = &buffer[0];
char* end = &buffer[buffer_sz];
begin = str_find_digit(begin, end);
if(begin == end)
{
	// error, no digit found
	return;
}
tmp_color[0] = strtoul(begin, &begin, 10);
if(tmp_color[0] > 255)
{
	// error
	return;
}

begin = str_find_digit(begin, end);
if(begin == end)
{
	// error, no digit found
	return;
}
tmp_color[1] = strtoul(begin, &begin, 10);
if(tmp_color[0] > 255)
{
	// error
	return;
}

begin = str_find_digit(begin, end);
if(begin == end)
{
	// error, no digit found
	return;
}
tmp_color[2] = strtoul(begin, 0, 10);
if(tmp_color[0] > 255)
{
	// error
	return;
}

// all went fine, assign to my_color
my_color.r = tmp_color[0];
my_color.g = tmp_color[1];
my_color.b = tmp_color[2];

i want to extract only numbers, 3 as RGB color 0-255 from input string called "buffer". Since user can change delimiters between numbers and maybie accidently insert less numbers then 3 i must account for that too.

But i got "Debug assertion" with my example:

Expression: (unsigned)(c+1)<=256

in str_find_digit function???
Topic archived. No new replies allowed.