C Program to Remove Comments and Blank lines from a valid C Program
Submitted by Srikanth on Saturday, 24 November 200710 Comments

This program accepts any valid C Program as an input and removes the comments and blanks from it. The output is a program that has no comments and blank lines.
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
void main()
{
FILE *a,*b;
FILE *a,*b;
char fname[20],ch,tch=NULL,tch1=NULL;
int flag1=0,flag=0,count=0,count1=0,count2=0;
clrscr();
clrscr();
printf(“Enter the file name (.C or .TXT)\n”);
gets(fname);
a=fopen(fname,”r”);
if(a==NULL)
{
puts(“Cannot open the source file!!!”);
delay(500);
exit(1);
}
b=fopen(“target.c”,”w”);
if(b==NULL)
{
puts(“Cannot create target file!!!”);
delay(500);
exit(1);
}
while(1)
while(1)
{
ch=fgetc(a);
if(ch==EOF) break;
else
else
{
if(ch==’\n’)
if(ch==’\n’)
{
count1=1;
tch1=ch;
continue;
}
else if(ch==’\n’&& count1==1)
else if(ch==’\n’&& count1==1)
continue;
else if(ch==’/'&&count==0)
{
flag1=1;
tch=ch;
count=1;
continue;
}
else if(ch==’*'&& flag1==1)
else if(ch==’*'&& flag1==1)
{
flag=1;
flag1=0;
tch=NULL;
}
else if(ch==’*'&&flag==1)
else if(ch==’*'&&flag==1)
{
count2=1;
count=1;
continue;
}
else if(ch==’/'&&count2==1)
else if(ch==’/'&&count2==1)
{
flag=0;
count=0;
tch=NULL;
continue;
}
else if(count==1&&flag==1)
else if(count==1&&flag==1)
count=0;
else if(flag1==1)
else if(flag1==1)
flag1=0;
}
if(flag!=1)
if(flag!=1)
{
if(tch>0)
fputc(tch,b);
if(tch1>0)
fputc(tch1,b);
tch1=NULL;
tch=NULL;
count=0,count1=0,count2=0;
fputc(ch,b);
flag1=0,flag=0;
}
}
puts(“DONE!! OP FILE IS \”TARGET.C\”\n”);
}
puts(“DONE!! OP FILE IS \”TARGET.C\”\n”);
fcloseall();
getch();
}
Popularity: 1% [?]
By using/following this site you agree to our Legal Disclaimer


Hi!I am browsing this web site from last two month , i want to suggest one thing that new information should be added every week because computer field has huge and interesting knowledge.
i am using this website for last two days . This website is very interesting.
thanks for your suggestion.. Will try to update my blog freequently.
HEY man you are great, how do you know all these things…………???????
HE i want borland c++ compiler 5.5 for free
Plz tell me the exact link where i can get it
I hve tried codegear website but i m not able 2 find where i can can it for free!!!
kindly help!!!
Thanx
I want borland c++ compiler 5.5
i hve turbo c++ but it is a 16 bit compiler
i want to change my software’s icon so can u tell me the exact URL for that???
plz help me I have tried codegear.com but i m not able 2 find it for free!!!
help me!!
Hey hi shri…
I learned many things cos of your web site buddy…kindly thanks a lot…!!!
The info provided by u is awesome n damn helpful.
Thanks a lot…
very big program but i will try
Leave your response!
EMAIL SECURITY »
What to Do When Your Email Account is Hacked?
How to Recover Hacked Email Accounts?
It can be a real nightmare if someone hacks and takes control of your email account as it may contain confidential information like bank logins, credit card details and other sensitive data. …
HOW STUFFS WORK »
How Antivirus Software Works
Due to ever increasing threat from virus and other malicious programs, almost every computer today comes with a pre-installed antivirus software on it. In fact, an antivirus has become one of the most essential software package for every computer. Even though every one …
HOW-TO GUIDES »
How to Hide Data in Image, Audio & Video Files: Steganography
Ever wondered to know how to hide secret messages in images, audio and video files? Well, in this post I will take you through a concept called steganography using which, it is possible to hide your secret information …
INTERNET SECURITY »
How to Hide Data in Image, Audio & Video Files: Steganography
Ever wondered to know how to hide secret messages in images, audio and video files? Well, in this post I will take you through a concept called steganography using which, it is possible to hide your secret information …
NETWORK HACKS »
How to Hack an Ethernet ADSL Router
Almost half of the Internet users across the globe use ADSL routers/modems to connect to the Internet however, most of them are unaware of the fact that it has a serious vulnerability which can easily be exploited even by a …
Categories
Most Popular
Most Commented
Blogroll
Log In | Entries (RSS) | Comments (RSS) | Sitemap
© 2008-2011 GoHacking.Com. This content is copyrighted to Srikanth and may not be reproduced on other websites.