Path: blob/master/languages/cprogs/Ex_1.23_remcomments.c
1240 views
/* Exercise 1.231*2* Program to remove comments from a C Program.3*4* Program should echo quotes and character constants properly5* C comments do not nest6*7*/89#include<stdio.h>1011void rcomment(int c);12void incomment(void);13void echo_quote(int c);1415int main(void)16{17int c,d;1819printf(" To Check /* Quoted String */ \n");2021while((c=getchar())!=EOF)22rcomment(c);2324return 0;25}2627void rcomment(int c)28{29int d;3031if( c == '/')32{33if((d=getchar())=='*')34incomment();35else if( d == '/')36{37putchar(c);38rcomment(d);39}40else41{42putchar(c);43putchar(d);44}45}46else if( c == '\''|| c == '"')47echo_quote(c);48else49putchar(c);5051}5253void incomment()54{55int c,d;5657c = getchar();58d = getchar();5960while(c!='*' || d !='/')61{62c =d;63d = getchar();64}65}6667void echo_quote(int c)68{69int d;7071putchar(c);7273while((d=getchar())!=c)74{75putchar(d);7677if(d == '\\')78putchar(getchar());79}80putchar(d);81}828384