This is what I am saying I think that this is not the correct approach.
You should write code that uncomments the data.Also your code should remove what is enclosed into < >
In other words you should just skip them and only when you read useful data do something with it .
For example this code will uncomment code in C ( well it is not completely correct but it works with simple cases)
Code:
#include <stdio.h>
int main(void)
{
int c=0;/*Must declare as int because of EOF*/
int next=0;/*We have to check the next character to find out if it is a comment*/
while ((c = getchar()) != EOF)
{
if(c == '/' )/*Possible start of comment*/
{
/*Notice were returned values of getchar are stored.This happens in order to be able to print them if they are not a comment*/
next = getchar();
if(next == '*')/*Is it really a start of comment?*/
{
c = getchar();
while(c == '*' )/*Eat all the asterics until the first occurence of a non-asterisc character*/
c = getchar();
while(c != '*')/*Eat letters,spaces,etc.*/
c = getchar();
next = getchar();
while(next == '*' )/*Eat all the asteriscs that might lie at the end of the comment*/
next = getchar();
if(next == '/')/*Eat the last slash of the comment.Careful not to eat them all*/
continue;
else
{
while(1)
{
c = getchar();
if(c == '*')
{
c = getchar();
if(c == '/')
break;
}
}
}
}
else/*It turned out it is not a comment,so just print what you get from buffer of stdin*/
{
putchar(c);
putchar(next);
}
}
else/*Sure not to be a comment so just print what you read*/
putchar(c);
}
return 0;
}
Run
Code:
Macintosh-c8bcc88e5669-9:hw2 usi$ ./u
/*jkdhsdjfh*/ int a; /*fjkdsfhjkds*/
int a;