Beispiel #1
0
int main( void )
{
    int c; // Character
    int ctriple[ 3 ]; // Character TRIPLE
    int cmnt[ 2 ]; // CoMmeNT

    cmnt[ LINE ] = FALSE;
    cmnt[ BLOCK ] = FALSE;

    /* ctripple[ 1 ] is assigned ctripple[ 2 ] in main(),
       and in incomment() ctripple[ 0 ] is assigned ctripple[ 1 ]
       and ctripple[ 1 ] is assigned ctripple[ 2 ]. By assigning
       ctriple[ 2 ] a NULL, ctriple[] won't have any funky memory artifacts. */
    ctriple[ 2 ] = '\0';

    while( ctriple[ 2 ] != EOF && ( c = getchar() ) != EOF )
    {
        ctriple[ 0 ] = ctriple[ 1 ];
        ctriple[ 1 ] = ctriple[ 2 ];
        ctriple[ 2 ] = c;
        if( !( incomment( ctriple, cmnt ) ) )
        {
            putchar( ctriple[ 2 ] );
        }
    }

    return 0;
}
void rcomment(int c)
{
    int d;
    if( c == '/')
    {
        if((d=getchar())=='*')
            incomment();
        else if( d == '/')
        {
            putchar(c);
            rcomment(d);
        }
        else
        {
            putchar(c);
            putchar(d);
        }
    }
    else if( c == '\''|| c == '"')
        echo_quote(c);
    else
        putchar(c);
}