|
INTERVIEW QUESTIONS
PROGRAMMING LANGUAGES
C
DETAILS
Question: Write a program to remove comment lines and blank lines from an error free c program.
Answer: NOTE: THIS PROGRAM WILL ONLY REMOVE THE COMMENTS (/*...*/) BUT NOT THE BLANK LINES.A PROGRAM 2 REMOVE COMMENTS AS WELL AS BLANK LINES WILL B SUBMITTED SOOOOON.THANKS.HERE'S DA PROGRAM
#include<stdio.h> #include<conio.h> #include<process.h> #include<dos.h> void main() { FILE *a,*b; char fname[20],ch,tch=NULL; int flag1=0,flag=0,count=0; clrscr(); printf("Enter the file name (.C or .TXT) "); gets(fname); a=fopen(fname,"r"); if(a==NULL) { puts("Cannot open the source file!!!"); delay(200); exit(1); } b=fopen("target.c","w"); if(b==NULL) { puts("Cannot create target file!!!aa"); delay(10); exit(1); } while(1) { start: ch=fgetc(a); if(ch==EOF) break; else { if(ch=='/'&&count==0) { flag1=1; tch=ch; count=1; continue; } else if(ch=='*'&& flag1==1) { flag=1; flag1=0; tch=NULL; } else if(ch=='*'&&flag==1) { count=1; continue; } else if(ch=='/'&&count==1) { flag=0; continue; } else if(count==1&&flag==1) count=0; } if(flag!=1) { if(tch>0) fputc(tch,b); tch=NULL; count=0; fputc(ch,b); flag1=0,flag=0; } } puts("DONE!! OP FILE IS "TARGET.C" "); fcloseall(); getch(); }
|
|
|
Category |
C Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 9073 users |
Added on |
10/23/2012 |
Views |
73325 |
Rate it! |
|
|
Question:
Write a program to remove comment lines and blank lines from an error free c program.
Answer:
NOTE: THIS PROGRAM WILL ONLY REMOVE THE COMMENTS (/*...*/) BUT NOT THE BLANK LINES.A PROGRAM 2 REMOVE COMMENTS AS WELL AS BLANK LINES WILL B SUBMITTED SOOOOON.THANKS.HERE'S DA PROGRAM
#include<stdio.h> #include<conio.h> #include<process.h> #include<dos.h> void main() { FILE *a,*b; char fname[20],ch,tch=NULL; int flag1=0,flag=0,count=0; clrscr(); printf("Enter the file name (.C or .TXT) "); gets(fname); a=fopen(fname,"r"); if(a==NULL) { puts("Cannot open the source file!!!"); delay(200); exit(1); } b=fopen("target.c","w"); if(b==NULL) { puts("Cannot create target file!!!aa"); delay(10); exit(1); } while(1) { start: ch=fgetc(a); if(ch==EOF) break; else { if(ch=='/'&&count==0) { flag1=1; tch=ch; count=1; continue; } else if(ch=='*'&& flag1==1) { flag=1; flag1=0; tch=NULL; } else if(ch=='*'&&flag==1) { count=1; continue; } else if(ch=='/'&&count==1) { flag=0; continue; } else if(count==1&&flag==1) count=0; } if(flag!=1) { if(tch>0) fputc(tch,b); tch=NULL; count=0; fputc(ch,b); flag1=0,flag=0; } } puts("DONE!! OP FILE IS "TARGET.C" "); fcloseall(); getch(); }
Source: CoolInterview.com
Answered by: Srikanth (sriki) | Date: 11/3/2007
| Contact Srikanth (sriki)
it showing one error............ Source: CoolInterview.com
Answered by: mahen | Date: 4/29/2010
| Contact mahen
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
Where is the prototype of the main function i.e how the execution startd from main function and how to find out the size of a function.
|
View Answer
|
|
The program that outputs the given binary or image file
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All C Interview Questions & Answers - Exam Mode /
Learning Mode
|