-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipaddress.cpp
More file actions
71 lines (45 loc) · 792 Bytes
/
ipaddress.cpp
File metadata and controls
71 lines (45 loc) · 792 Bytes
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
#include"essentials.cpp"
bool check_ip(string ip){
int dots=0;
int i=0;
int l=ip.length();
if(ip[i]=='.'){
cout<<"hi1"<<endl;
return false;
}
while(i<l){
int num=0;
while( i<l && ip[i]!='.'){
char c=ip[i++];
if(c<'0' || c>'9'){
return false;
}
num=(num*10)+(c-'0');
}
if(i<l){
++dots;
}
if(dots>3 || num<0 || num>255){
cout<<"hi3"<<endl;
return false;
}
++i;
}
if(dots!=3){
cout<<"hi4"<<endl;
return false;
}
else{
return true;
}
}
int main(){
// char ip1[] = "128.0.0.1";
// char ip2[] = "125.16.100.1";
// char ip3[] = "125.512.100.1";
// char ip4[] = "125.512.100.abc";
string ip5="128.212.145.123";
string ip6="256.123.12.110";
check_ip(ip6)? printf("Valid\n"): printf("Not valid\n");
return 0;
}