1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

removing comments of type // and /*

Discussion in 'C' started by rohit83.ken, Oct 19, 2007.

  1. rohit83.ken

    rohit83.ken New Member

    Joined:
    Oct 19, 2007
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    please 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

    kindly send the source code or provide link
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    This is not a free software store. You should either

    1) Attempt to write the code and ask here for help with your problems.
    2) Put your request in the Job Offers forum.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    I can share the algo with you.

    Parse the characters of the file and check for // or /* but remember that they should not be under the string literal ""

    Now if you find // which is not under the string literal then ignore the line
    if you find /* and its not in the string literal then ignore till */
    Else you write everything to the new file.

    I hope it helps.
     

Share This Page