You are on page 1of 1

System Programming 2150708

Aim: Write a Program to take a C file as input and remove comments


from the file
Source Code:
#include<stdio.h>
#include<file.h>
int main(){

FILE *FI,*FO;
char ch;
FI=fopen("file1.c","r");
FO=fopen("output.c","w");
ch=getc(FI);
while(ch!=EOF){
if(ch=='/'){
ch=getc(FI);
if(ch=='/'){
while(ch!='\n') //while loop{
ch=getc(FI);
}
}
if(ch=='*'){
while(ch!=EOF){
ch=getc(FI);
if(ch=='*'){
ch=getc(FI);
if(ch=='/')
break;
}
}
}
ch=getc(FI);
}
putc(ch,FO);
ch=getc(FI);

}
close(FI);
close(FO);
}

Output:
In Output comments will be removed from file.c

#include<stdio.h>
void main(){
printf(“Hello World ”);
}

160110107007 Page 1

You might also like