Switch Statement

I'm building a switch statement where I want to include ranges in the case part. Is this correct?

1
2
3
4
5
6
7
8
9
10
11
switch (x){
case 1 to 10:
z=a;
break;
case 11 to 20:
z=b;
break;
default;
z=c
break;
}


I also have statements like this. Will they work?
case (strncmp("10.", ipSrc, 3)
Last edited on
I'm pretty sure that won't work. Switch statements are for evaluating integers, or data that can be cast to an integer, not bools.
Thank you. How about a map? I have all of these IP address's and IP address ranges that I have to query and the if statement with or is getting big!
I don't see how you would go from the switch statement you defined above to anything like what you are describing with regards to an std::map. In an attempt to stick with your example above, where does "x" come from in your dilema?
Ok here is the real info. I tried to keep it simple before.

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
switch (ipSrc){
	case (strncmp("192.168", ipSrc, 7): //Local
		ipSrc=0;
		break;
	case (strncmp("10.", ipSrc, 3): //Local
		ipSrc=0;
		break;	
	case (strncmp("172", ipSrc, 3): //Go Daddy
		ipSrc=0;
		break;
	case 70.39.129.151: //Go Daddy
		ipSrc=0;
		break;
	case (strncmp("65.55.158.118", ipSrc,13): //Microsoft Updates
		ipSrc=0;
		break;
	case (ip_header->source_ip == sockAddr.sin_addr.s_addr)):
		ipSrc=0;
		break;
	case 64.233.160.0 - 64.233.191.255: //Google 
		ipSrc=0;
		break;
	case 66.102.0.0 - 66.102.15.255: //Google
		ipSrc=0;
		break;
	case 66.249.64.0 - 66.249.95.255: //Google 
		ipSrc=0;
		break;
	case 72.14.192.0 - 72.14.255.255: //Google 
		ipSrc=0;
		break;
	case 74.125.0.0 - 74.125.255.255: //Google 
		ipSrc=0;
		break;
	case 209.85.128.0 - 209.85.255.255: //Google 
		ipSrc=0;
		break;
	case 216.239.32.0 - 216.239.63.255: //Google
		ipSrc=0;
		break;
	case 67.195.160.76: //Yahoo 
		ipSrc=0;
		break;
	case 69.147.125.65: //Yahoo 
		ipSrc=0;
		break;
	case 72.30.2.43: //Yahoo 
		ipSrc=0;
		break;
	case 98.137.149.56: //Yahoo 
		ipSrc=0;
		break;
	case 209.191.122.70: //Yahoo
		ipSrc=0;
		break;
	case 98.139.180.149: //Yahoo
		ipSrc=0;
		break;
	case 173.201.0.0 - 173.201.255.255: //Packet Exchange
		ipSrc=0;
		break;
	case 67.82.251.182: //Packet Exchange
		ipSrc=0;
		break;
	default:
	}

Ok, so this is sort of like using "ping -a xxx.xxx.xxx.xxx". This is a trickey one, I'm not sure how I would go about this if I would go this route at all. I'll think about it for a minute.
Topic archived. No new replies allowed.