[comp.lang.c] stream sampler needed

MISS026%ECNCDC.BITNET@wiscvm.wisc.EDU (GREENY) (07/09/87)

Hi all...

I was wondering if anyone had any source code to sample a continous
stream of data, throwing away (/dev/null) what wasnt sampled.  Basically
i have a continous stream of data and I would like to wait until I
get a specific character, and then capture the next 13 characters.

Any suggestions? Im trying not to re-invent the wheel or do something the
long way....

bye for now but not for long...
Greeny

Bitnet: Miss026@ecncdc
Internet: miss026%ecncdc.bitnet@wiscvm.wisc.edu

Disclaimer: What? Who? me? nope...not me...you *must* have the wrong hacker

greg@utcsri.UUCP (07/13/87)

>I was wondering if anyone had any source code to sample a continous
>stream of data, throwing away (/dev/null) what wasnt sampled.  Basically
>i have a continous stream of data and I would like to wait until I
>get a specific character, and then capture the next 13 characters.

Sounds very suspicious to me.

>Any suggestions? Im trying not to re-invent the wheel or do something the
>long way....  
>
No. However, I have a program which changes all occurrences of 'n' in an odd-
numbered column of the input to 'E'. I don't need it any more, but have been
saving it in case anyone else needs it and doesn't want to re-invent the wheel.

-- 
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg
Have vAX, will hack...

jfh@killer.UUCP (John Haugh) (07/15/87)

In article <8233@brl-adm.ARPA>, MISS026%ECNCDC.BITNET@wiscvm.wisc.EDU (GREENY) writes:
> Hi all...
> 
> I was wondering if anyone had any source code to sample a continous
> stream of data, throwing away (/dev/null) what wasnt sampled.  Basically
> i have a continous stream of data and I would like to wait until I
> get a specific character, and then capture the next 13 characters.

This is too easy - but into the mire I fall ...

-------------------------- cut somewheres near here -----------------
/*
 * Does the above requested task with no error checking
 */

sample (fp, c, n, s)
FILE	*fp;		/* input stream */
char	c;		/* character to look for */
int	n;		/* number of characters to copy after `c' */
char	*s;		/* where to put them */
{
	int	in;

	while ((in = getc (fp)) != c)
		;

	while (n-- > 0)
		*s++ = getc (fp);
}

This had better not be a joke ...

- john.