Code:
//a program which works as a preprocess removes comments in a given program
#include<stdio.h>
main()
{
int i,start,end;
char array[500],c;
for(i=0;(c=getchar())!=EOF;i++)
array[i]=c;
for(i=0;array[i]!=EOF;i++)
{
if( (array[i]=='/') && (array[i+1]=='*') )
start=i;
if( (array[i]=='*') && array[i+1]=='/')
{
end=i+1;
for(i=start;i<=end;i++)
array[i]='\b';
}
}
//for(i=start;i<=end;i++)
// array[i]='\0';
printf("after comments removal the text is as below\n");
for(i=0;array[i]!=EOF;i++)
putchar(array[i]);
printf("\n");
}
here i have created a demo code which works similar to a pre processor which removes the comments in the given program but this is yielding nasty results debug my program please
INPUT to program:
Code:
/*comment1*/
statement1;
/*comment2*/
statement2;
/*comment3*/
statement3;
OUTPUT:
Code:
after comments removal the text is as below
statement1;
statement2;
statement3;�q*Дq�$Дq�@(u�q@
im supposed to remove the comments BUT THE BLANK SPACES REMAIN HOW TO REMOVE THEM???
also i get unwanted character at the end ,what changes can i do to my program
moreover here i want to give a .c file as input to program how could i do that in linux
can i try code.c | ./program