Remove comments

This is a discussion on Remove comments within the C Programming forums, part of the General Programming Boards category; 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 ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 04:18 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. The Art of Writing Comments :: Software Engineering
    By kuphryn in forum C++ Programming
    Replies: 15
    Last Post: 11-23-2002, 04:18 PM
  5. remove comments from source code
    By limbo100 in forum C Programming
    Replies: 2
    Last Post: 09-29-2001, 06:25 PM

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