summaryrefslogtreecommitdiff
path: root/C/HF/categorize.c
blob: a4552243720e86b2764f14ef37d6d63016525906 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void
usage(char *program)
{
	printf("Usage:\n");
	printf("\t%s: <filter1> <output_file_1> <filter2> <output_file_2> <everything>\n",
	       program);
	exit(1);
}

int
main(int argc, char *argv[])
{
	char line[80];
	FILE *in;
	FILE *file1;
	FILE *file2;
	FILE *file3;

	if (argc != 6)
		usage(argv[0]);

	in = fopen("spooky.csv", "r");
	file1 = fopen(argv[2], "w");
	file2 = fopen(argv[4], "w");
	file3 = fopen(argv[5], "w");

	while (fscanf(in, "%79[^\n]\n", line) == 1) {
		if (strstr(line, argv[1]))
			fprintf(file1, "%s\n", line);
		else if (strstr(line, argv[3]))
			fprintf(file2, "%s\n", line);
		else
			fprintf(file3, "%s\n", line);
	}

	fclose(in);
	fclose(file1);
	fclose(file2);
	fclose(file3);
	return 0;
}