help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $x value lost?


From: Bruce Lilly
Subject: Re: $x value lost?
Date: Tue, 11 Mar 2003 09:36:08 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130

Mhaxx wrote:

I don't understande where is the problema about printf.

char *s = "a%sb%dc%xe";
printf(s);
is a problem because printf will look for additional arguments
which are not supplied.
char *s = "a%sb%dc%xe";
printf("%s", s);
is OK as the content of s doesn't matter as long as it points
to a nul-terminated string.

> What does "puts()"
do and what does your parser do?

Briefly, puts() outputs a string to stdout. There is a man page
which gives details. Try "man puts" or consult other
documentation for details.
puts(s);
will yield the same result as
printf("%s", s);
but is faster as printf has to interpret the format string, while
puts does not.  If you're just printing a plain string and do not
need to interpret a format string, use puts or fputs rather than
printf or fprintf; your code will be more robust on unexpected
input, will be easier to maintain and understand, and will
execute more efficiently.

All of which is basic C programming and not specific to flex.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]