GeeksforGeeks » Interview Questions
coding
(3 posts)-
how will you validate IP address or write a function which tell you if the IP adress given by you is valid or not?
-
int is_valid_ip(const char *ip_str) { unsigned int n1,n2,n3,n4; if(sscanf(ip_str,"%u.%u.%u.%u", &n1, &n2, &n3, &n4) != 4) return 0; if((n1 != 0) && (n1 <= 255) && (n2 <= 255) && (n3 <= 255) && (n4 <= 255)) return 1; return 0; } -
This question was asked from one of my friend in an interview at Cloud.com in hyderabad.
Reply
You must log in to post.