Example: an "fgrep-like" filter using astrings



This code is capable of handling long lines without buffer overrun.
Important! Warning! All libmib example code is shown for reference only. It comes with no warranty whatsoever. This example code probably does NOT match current libmib sources. It may contain defects and may have only a subset of features. Use and distribution is permitted according to the libmib license.
	#include <stdio.h>
	#include <libmib/astring.h>
	main(int argc,char **argv)
	{
	char *pasz = 0;
	long line = 0;

		if (argc != 2) {
			asprintf(&pasz,"usage: %s \"text to find\" <file\n",argv[0]);
			fputs(pasz,stderr);
			exit(-1);
		}
		while(afgets(&pasz,stdin)) {
			if (strstr(pasz,argv[1]) {
			   printf("%ld:",line);
			   fputs(pasz,f);
			}
			line++;
		}
	}
Important! Warning! All libmib example code is shown for reference only. It comes with no warranty whatsoever. This example code probably does NOT match current libmib sources. It may contain defects and may have only a subset of features. Use and distribution is permitted according to the libmib license.
Overview and Related Topics
Up to: Libmib Allocated String Functions
Up to: Libmib: Character String Processing
Up to: Libmib

This Libmib documentation may not be distributed. Copyright 1998, Forrest J. Cavalier III
Mib Software
High Reuse Software Development