Thread: Remove comments

  1. #1
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127

    Remove comments

    hi all
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    #define BUF 250
    main()
    {
          FILE *fp;
          char buffer[BUF];
          int count;
          char *loc;
          if((fp=fopen("New Text Document.txt","r"))==NULL)
          {
          printf("Error");
          exit(0);
          }
          
          while((fgets(buffer,BUF,fp))!=NULL)
          {
                                             
                                             if(loc=strstr(buffer,"/*"))
                                              {
                                                                        
                                              buffer[loc-buffer]='\0';                    
                                              }
                                                                                            
                                                                                            
                                                                                                                               
                                                 printf("%s\n",buffer);
                                                 }
                                                 
                                                 
                                                 fclose(fp);
                                                 }
    your advices pleas ;
    thanks

  2. #2
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127
    about fopen("New Text Document.txt","r"))
    never mind about it i am to lazy to take user input at now

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Fix indentation?

    No wait, we've done that sketch already...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127
    heeeeeeeeeeeheeeeeeeeeeeeeeeheeeeeeeeeeeeeee
    i am in a way over my head in indentation i hate dev cpp compiler
    but tell me is the code is o.k !

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you should test the code by yourself before asking if it is ok
    Code:
    int main(/* no args*/)
    {
    /*
     * Now the important part - variable iniitialization
     */
     int i = /* let's initialize it with something*/ 0;
    }
    give it as input and see what is the output...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. removing comments of type '//' and '/*'
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 10-20-2007, 02:24 AM
  2. program to remove comments from source
    By Abda92 in forum C Programming
    Replies: 12
    Last Post: 12-25-2006, 05:18 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. The Art of Writing Comments :: Software Engineering
    By kuphryn in forum C++ Programming
    Replies: 15
    Last Post: 11-23-2002, 05:18 PM
  5. remove comments from source code
    By limbo100 in forum C Programming
    Replies: 2
    Last Post: 09-29-2001, 06:25 PM