Thread: removing comments of type '//' and '/*'

  1. #1
    Registered User
    Join Date
    Oct 2007

    Question removing comments of type '//' and '/*'

    help me in writing the code that takes a c or c++ file and deletes the comments and prints the output to other file

    totally 3 files r involved
    one removes the comments
    other is the program having comments
    other is output printed without any comments containing c or c++ code

    prethanks to the helper

    send the source code or provide link

  2. #2
    The larch
    Join Date
    May 2006
    This forum does not provide source code.

    That could be implemented as a state machine: while iterating over the input your program will be either in a "inside-a-comment" or "out-side-a-comment" state, outputting to the other file only in the latter case.

    This might be rather tricky as you'd also have to take into account that you may meet // inside a quote "//this is a string not a comment" and possibly malformed comments.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    Filed under "idiot."

    If you're going to demand that other people help you cheat on an assignment, the least you could do is use the word "please."

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Blatant homework rule violation.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed