File:  [MW Coherent from dump] / coherent / d / usr / src / examples / fgetc.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:38 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

#include <stdio.h>

main()
{
	FILE *fp;
	int ch;
	int filename[20];
	int nlines = 0;
	int nsents = 0;

	printf("Enter file to test: ");
	gets(filename);

	if ((fp = fopen(filename,"r")) == NULL) {
		printf("Cannot open %s.\n", filename);
		exit(1);
	}
	while ((ch = fgetc(fp)) != EOF) {
		if (ch == '\n')
			++nlines;
		else
			if (ch == '.' || ch == '!' 
					|| ch == '?') {
				if ((ch = fgetc(fp)) != '.') 
					++nsents;
				else 
					while 
					((ch=fgetc(fp)) == '.')
						;                              
				ungetc(ch, fp);
			}
	} 				
	printf("%d line(s), %d sentence(s).\n", nlines, nsents);
}


unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.