Skip to content

Remove Inline Comments in a Source Code

October 14, 2012

/* this program ignores all user comments written in the source 
code and writes into a designated target file */

/* Don't just use(Ctrl+c) & (Ctrl+v); It will decrease your 
programming skill */

#include<stdio.h>
#include<string.h>

int main(){

char inp[100];
 FILE *fp, *op;
 int flag=0;
 fp=fopen("input.cpp", "r");
 op=fopen("output.cpp","w");

while(fgets(inp,100,fp)){
 int j=0;
 int l=strlen(inp);

for(int i=0; i<l; i++){

if(inp[i] =='/' && inp[i+1]=='/')
 break;
 if(inp[i] =='/' && inp[i+1]=='*')
 flag=1;

if(flag==0)
 inp[j++]=inp[i];
 if(inp[i-1] =='*' && inp[i]=='/')
 flag=0;
}

inp[j]='';
 fprintf(op,"%s",inp);
}

return 0;
 }
Advertisements

From → Programming, Random

2 Comments
  1. Autul permalink

    Good job man …. matha nosto puraiii 😀

    • Thanks man !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: