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. Validation of matching comments

Validation of matching comments

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
7 Posts 6 Posters 2 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.
  • R Offline
    R Offline
    reddy harish
    wrote on last edited by
    #1

    Hi i want to validate the matching comments.(/* */).Every file should start with the /* and should end with */. if he gives multiple comments it sholud not be validate. Here iam showing some possible example which user may enter. 1./*text*//* 2./*text*/*/ 3./*text/**/ but that should be only /*text*/.other than this situation i need to throw an error.he is entering the file in edit box. please any one can give me the solution for this problem.

    Z M M C 4 Replies Last reply
    0
    • R reddy harish

      Hi i want to validate the matching comments.(/* */).Every file should start with the /* and should end with */. if he gives multiple comments it sholud not be validate. Here iam showing some possible example which user may enter. 1./*text*//* 2./*text*/*/ 3./*text/**/ but that should be only /*text*/.other than this situation i need to throw an error.he is entering the file in edit box. please any one can give me the solution for this problem.

      Z Offline
      Z Offline
      Zac Howland
      wrote on last edited by
      #2

      Load the file into memory and use the boost::RegEx class to validate it. For more information, check out boost.org.

      If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

      1 Reply Last reply
      0
      • R reddy harish

        Hi i want to validate the matching comments.(/* */).Every file should start with the /* and should end with */. if he gives multiple comments it sholud not be validate. Here iam showing some possible example which user may enter. 1./*text*//* 2./*text*/*/ 3./*text/**/ but that should be only /*text*/.other than this situation i need to throw an error.he is entering the file in edit box. please any one can give me the solution for this problem.

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        hint : use a stack when scanning the file.


        Maximilien Lincourt Your Head A Splode - Strong Bad

        1 Reply Last reply
        0
        • R reddy harish

          Hi i want to validate the matching comments.(/* */).Every file should start with the /* and should end with */. if he gives multiple comments it sholud not be validate. Here iam showing some possible example which user may enter. 1./*text*//* 2./*text*/*/ 3./*text/**/ but that should be only /*text*/.other than this situation i need to throw an error.he is entering the file in edit box. please any one can give me the solution for this problem.

          M Offline
          M Offline
          MayankT
          wrote on last edited by
          #4

          Search for '/*' in the file. It should be found only once and the offset should be 0. Then search for '*/' in the file. Again this should be found only once and offset should be at end of file.

          reddy harish wrote:

          he is entering the file in edit box

          I assumed you have access to the file contents in a string so you can use string::find

          ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

          1 Reply Last reply
          0
          • R reddy harish

            Hi i want to validate the matching comments.(/* */).Every file should start with the /* and should end with */. if he gives multiple comments it sholud not be validate. Here iam showing some possible example which user may enter. 1./*text*//* 2./*text*/*/ 3./*text/**/ but that should be only /*text*/.other than this situation i need to throw an error.he is entering the file in edit box. please any one can give me the solution for this problem.

            C Offline
            C Offline
            CoolASL
            wrote on last edited by
            #5

            I dont think that it would require any special programming. Whenever you get a /*, you will have to search for a */. If you get any /* nested inside a /*, then you will have to ignore it. Set a flag to indicate that you have already got a /*, then ignore subsequent /* while the flag is on. When you get a */, just put off the flag and consider the whole part as a commented area. Hope it helps.

            *** Who said nothing is impossible? I have been doing it for a long time ***

            S 1 Reply Last reply
            0
            • C CoolASL

              I dont think that it would require any special programming. Whenever you get a /*, you will have to search for a */. If you get any /* nested inside a /*, then you will have to ignore it. Set a flag to indicate that you have already got a /*, then ignore subsequent /* while the flag is on. When you get a */, just put off the flag and consider the whole part as a commented area. Hope it helps.

              *** Who said nothing is impossible? I have been doing it for a long time ***

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              I don't think it will be quite that simple. For example what happens if a "//", "/*" or "*/" is inside quotes?

              Steve

              C 1 Reply Last reply
              0
              • S Stephen Hewitt

                I don't think it will be quite that simple. For example what happens if a "//", "/*" or "*/" is inside quotes?

                Steve

                C Offline
                C Offline
                CoolASL
                wrote on last edited by
                #7

                well, steve, what i suggested was the simplest way and the basic algorithm. If the need of checking inside strings is required, then it could very well be checked too. There could be several other requirements too. All of them could be simply built over that basic algo.

                *** Who said nothing is impossible? I have been doing it for a long time ***

                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