Skip to content

Commit c37ac9e

Browse files
author
Margo
committed
Add code for 11/10 exercise
1 parent 08e15e7 commit c37ac9e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

shell3x/GNUmakefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ALLPROG=sieve
2+
all: $(ALLPROG)
3+
O ?= -O2
4+
5+
include ../common/rules.mk
6+
7+
%: %.o $(BUILDSTAMP)
8+
$(CC) $(LDFLAGS) -o $@ $<
9+
10+
%.o: %.c $(BUILDSTAMP)
11+
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEPCFLAGS) $(O) -o $@ -c $<
12+
13+
clean:
14+
rm -f $(ALLPROG) *.o
15+
rm -rf $(DEPSDIR) *.dSYM
16+
17+
.PHONY: all clean

shell3x/sieve.c

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <sys/stat.h>
2+
#include <sys/types.h>
3+
#include <sys/wait.h>
4+
#include <assert.h>
5+
#include <errno.h>
6+
#include <fcntl.h>
7+
#include <stdio.h>
8+
#include <stdio_ext.h>
9+
#include <stdlib.h>
10+
#include <string.h>
11+
#include <unistd.h>
12+
13+
// Fork a child, who reads from my stdout.
14+
// Then, read from standard in.
15+
// Output the first thing read to stderr
16+
// Then write everything after it to standard out, removing anything that
17+
// is a multiple of that first value.
18+
int main(int argc, char *argv[]) {
19+
(void)argc;
20+
(void)argv;
21+
22+
int val;
23+
24+
// Read first value and output to stderr
25+
if (scanf("%d ", &val) != 1)
26+
exit(1);
27+
fprintf(stderr, "%d ", val);
28+
29+
// TODO: Read values from your standard input and write them to
30+
// your standard output if they are not a multiple of val.
31+
}

0 commit comments

Comments
 (0)