Mail Archives: djgpp/1997/04/01/18:28:03
> In the beginner I set a string called 'test_string'
>
> char test_string[5] ;
> #197; <--End of test string
> When I checks if test_string is equal to a special character:
>
> if (test_string =3D=3D "#197; ") printf("I should see this");
> if (test_string =3D=3D "#197;") printf("or this");
This program would IMHO be a perfect candidate for Flex. I wrote a
simple text to html scanner in seriously less than 3 minutes.
But - your problem seems to be that you are confusing BASIC with C.
You cannot use the == operator on string values. Use strcmp instead
#include <string.h>
if (strcmp(test_string,"#197;")==0) printf("I should see this");
In Flex you could do something like this
mylexer.l
----------------------------
%%
#197 { fprintf(yyout,"Special Value 1"); }
#198 { fprintf(yyout,"Special Value 2"; }
---------------------------------------------------
Thats it. Add lines as needed for the codes you want to replace.
build it with
flex mylexer.l
gcc -DYY_MAIN lexyy.c -o mylexer -lfl
run it like so
mylexer < foo.htm > foo.txt
(I did test this by the way)
Aside from being less code (no main routine, no manual compares,
no get character and append stuff) its most likely faster than
anything you can hand code.
Andrew
- Raw text -