68d622772415 — pouya@nohup.io tip 5 months ago
initial commit
4 files changed, 76 insertions(+), 0 deletions(-)

A => Makefile
A => dat.h
A => fns.h
A => main.c
A => Makefile +23 -0
@@ 0,0 1,23 @@ 
+CC=pcc
+LD=pcc
+
+CCFLAGS=-O
+LDFLAGS=-static
+
+TARG=nstats
+OFILES=main.o
+
+all: ${TARG}
+
+clean:
+	rm -f *.o ${TARG}
+
+.SUFFIXES: .c .o
+
+.c.o:
+	${CC} ${CCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
+
+${TARG}: ${OFILES}
+	${LD} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET}
+
+.PHONY: all clean

          
A => dat.h +1 -0
@@ 0,0 1,1 @@ 
+#define nil (void *)0

          
A => fns.h +0 -0

A => main.c +52 -0
@@ 0,0 1,52 @@ 
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dat.h"
+#include "fns.h"
+
+#ifndef BUFLEN
+#define BUFLEN 1024
+#endif
+
+int
+main() {
+	int i, ib, eof;
+	char bufc[BUFLEN], *b;
+	float f, min, max, mean;
+
+	min = 1.0/0.0;
+	max = -1.0/0.0;
+	mean = 0.0;
+
+	i = eof = 0;
+	while(!eof) {
+		ib = 0;
+		b = bufc;
+		while(++ib < (sizeof bufc)/(sizeof bufc[0])) switch(*b++ = getchar()) {
+		case EOF:
+			eof = 1;
+		case '\n':
+		case '\r':
+		case '\t':
+		case ' ':
+			b--;
+			ib--;
+			goto eofield;
+		default:
+			break;
+		}
+eofield:
+		if(ib) {
+			*b = 0;
+			f = atof(bufc); /* sizeof bufc must be > 1 */
+			if(f < min) min = f;
+			if(f > max) max = f;
+			mean = (mean*i+f)/(++i);
+		}
+	}
+
+	printf("min:  %g\nmax:  %g\nmean: %g\n", min, max, mean);
+	return 0;
+}