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

This is a discussion on removing comments of type '//' and '/*' within the C++ Programming forums, part of the General Programming Boards category; help me in writing the code that takes a c or c++ file and deletes the comments and prints the ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    6

    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
    Posts
    3,573
    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    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
    Posts
    8,893
    Blatant homework rule violation.
    All the buzzt!
    CornedBee

    "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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21