Re: Redirect stdin ?
- From: William Pursell <bill.pursell@xxxxxxxxx>
- Date: Mon, 31 Dec 2007 09:24:22 -0800 (PST)
On Dec 31, 1:40 pm, Lothar Behrens <lothar.behr...@xxxxxxxxxxxx>
wrote:
I have a c application (Lex&Yacc based) that parses from stdin. I want
to rewrite the code
a bit to allow reading the source from a char array instead from stdin
without touching the
lex and yacc generated source code.
How could I do that ?
What is about the problem when the buffer is too big to feed the
source to the parser at once ?
Any ideas ?
If you are okay with using gcc extensions, here's a section
from the glibc info pages you might find interesting:
Here is an example of using `fmemopen' to create a stream for
reading from a string:
#include <stdio.h>
static char buffer[] = "foobar";
int
main (void)
{
int ch;
FILE *stream;
stream = fmemopen (buffer, strlen (buffer), "r");
while ((ch = fgetc (stream)) != EOF)
printf ("Got %c\n", ch);
fclose (stream);
return 0;
}
This program produces the following output:
Got f
Got o
Got o
Got b
Got a
Got r
.
- Follow-Ups:
- Re: Redirect stdin ?
- From: Harald van Dijk
- Re: Redirect stdin ?
- References:
- Redirect stdin ?
- From: Lothar Behrens
- Redirect stdin ?
- Prev by Date: Re: Cannot compile with _FILE_OFFSET_BITS = 64
- Next by Date: Re: Cannot compile with _FILE_OFFSET_BITS = 64
- Previous by thread: Redirect stdin ?
- Next by thread: Re: Redirect stdin ?
- Index(es):
Relevant Pages
|