Demonstration to uncomment the “C” program.
#include
main (int argc, char *argv[] )
{
int i = 1 , flag = 0 , quote = 0;
char buf[100][80];
int printflag = 1, end_cmt = 0 ,begin_cmt = 1 ;
if ( argc != 3 )
{
fprintf ( stderr ," Usage : a.out \n" );
exit (0 );
}
FILE *fp ;
int line = 0, index = 0 ;
if ( (fp = fopen ( argv[1] , "r" )) == NULL )
{
fprintf ( stderr ,"File not found\n");
exit ( 1);
}
while ( i )
{
i = fgetc ( fp );
if ( i == EOF )
break;
buf[line][index] = i ;
index++;
if ( buf[ line ][ index - 1 ] == '\n' )
{
line++ ;
index = 0;
}
}
fclose ( fp );
buf[ line ][ ++index] = i ;
line = 0;
index = 0;
fp = fopen (argv[2] , "w" );
while ( 1 )
{
if ( buf[ line ][ index ] == '"' && quote == 0 )
quote = 1;
else if ( buf[ line ][ index ] == '"' && quote == 1 )
quote = 0;
if ( quote == 0 && buf[ line ][ index] == '/' &&
buf[ line ][ index + 1 ] == '*' )
{
begin_cmt = 1;
index += 2;
continue;
}
else
if ( quote == 0 && begin_cmt == 1 && buf[ line ][ index ] == '*'
&& buf[ line ][ index + 1 ] == '/' )
{
begin_cmt = 0;
index += 2 ;
continue ;
}
else if ( quote == 0 && buf[ line ][ index ] == '/' &&
buf[ line ][ index + 1 ] == '/' )
{
if (begin_cmt == 1 )
begin_cmt = 2;
else
begin_cmt = 3;
index += 2;
continue;
}
fprintf ( fp ,"%c", buf [ line ][ index ] );
index++;
if ( buf[ line ][ index - 1 ] == '\n' && (begin_cmt == 2 ||
begin_cmt == 3 ) )
{
line++ ;
if ( begin_cmt == 3)
begin_cmt = 0;
else
begin_cmt = 1;
index = 0;
}
else if ( buf[ line ][ index - 1 ] == '\n' )
{
line++ ;
index = 0;
}
if ( buf [line][index] == EOF )
break;
}
fprintf ( fp , "\n\n");
fclose ( fp );
}
Note: This program works well in UNIX environment.
Code contributed by : Pradeep SP
pradeepcse23@gmail.com