Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Please give the correct ans of my question

Please give the correct ans of my question

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    piyush kr maurya
    wrote on last edited by
    #1

    Write a function to check that a given string is a valid IP address. An IP address is of the form a.b.c.d where a,b,c,d are numbers in the range 0-255 without a leading zero. You are not allowed to use any string methods like split, indexof, parseInt etc, in C language

    G T M M C 5 Replies Last reply
    0
    • P piyush kr maurya

      Write a function to check that a given string is a valid IP address. An IP address is of the form a.b.c.d where a,b,c,d are numbers in the range 0-255 without a leading zero. You are not allowed to use any string methods like split, indexof, parseInt etc, in C language

      G Offline
      G Offline
      Garth J Lancaster
      wrote on last edited by
      #2

      its actually quite easy, but :- 1) sounds like homework - DO YOUR OWN 2) I dont like 'Please give the correct ans' - people here give the best answer they know according to their experience & knowledge, and dont mislead/give deliberatly wrong answers, so I take offence to this 'g'

      1 Reply Last reply
      0
      • P piyush kr maurya

        Write a function to check that a given string is a valid IP address. An IP address is of the form a.b.c.d where a,b,c,d are numbers in the range 0-255 without a leading zero. You are not allowed to use any string methods like split, indexof, parseInt etc, in C language

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        In C language there is nothing like IndexOF,ParseInt and splits.. you can use strstr to find '.' and atoi to convert strings to number

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
        Never mind - my own stupidity is the source of every "problem" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

        1 Reply Last reply
        0
        • P piyush kr maurya

          Write a function to check that a given string is a valid IP address. An IP address is of the form a.b.c.d where a,b,c,d are numbers in the range 0-255 without a leading zero. You are not allowed to use any string methods like split, indexof, parseInt etc, in C language

          M Offline
          M Offline
          Michel Godfroid
          wrote on last edited by
          #4

          #include <regex.hpp> int match(const char * what) { return(regex_match(what,"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$") } That should impress your teacher... ;P

          1 Reply Last reply
          0
          • P piyush kr maurya

            Write a function to check that a given string is a valid IP address. An IP address is of the form a.b.c.d where a,b,c,d are numbers in the range 0-255 without a leading zero. You are not allowed to use any string methods like split, indexof, parseInt etc, in C language

            M Offline
            M Offline
            markkuk
            wrote on last edited by
            #5

            The correct way to check IP4 addresses for validity is:

            bool validate_addr(const char* ip)
            {
            return inet_addr(ip) != INADDR_NONE;
            }

            M R 2 Replies Last reply
            0
            • P piyush kr maurya

              Write a function to check that a given string is a valid IP address. An IP address is of the form a.b.c.d where a,b,c,d are numbers in the range 0-255 without a leading zero. You are not allowed to use any string methods like split, indexof, parseInt etc, in C language

              C Offline
              C Offline
              Chris Losinger
              wrote on last edited by
              #6

              do your own homework

              image processing toolkits | batch image processing

              1 Reply Last reply
              0
              • M markkuk

                The correct way to check IP4 addresses for validity is:

                bool validate_addr(const char* ip)
                {
                return inet_addr(ip) != INADDR_NONE;
                }

                M Offline
                M Offline
                Michel Godfroid
                wrote on last edited by
                #7

                Yes, but it does not follow the requirements. inet_addr will accept any dot notation, so "4.003.002.0x10" will be valid. I think the purpose of the exercise is to lead gently to stuff like atoi(), format strings, and so on...

                1 Reply Last reply
                0
                • M markkuk

                  The correct way to check IP4 addresses for validity is:

                  bool validate_addr(const char* ip)
                  {
                  return inet_addr(ip) != INADDR_NONE;
                  }

                  R Offline
                  R Offline
                  Rozis
                  wrote on last edited by
                  #8

                  I agree on your answer - clever

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups