GeeksforGeeks » Interview Questions

coding

(3 posts)
  1. kingkong
    guest
    Posted 1 year ago #

    how will you validate IP address or write a function which tell you if the IP adress given by you is valid or not?

  2. king kong
    guest
    Posted 1 year ago #

    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;
    }
    
  3. guest007
    guest
    Posted 1 year ago #

    This question was asked from one of my friend in an interview at Cloud.com in hyderabad.


Reply

You must log in to post.

RSS feed for this topic