~earboxer/SwipeBehaviors

SwipeBehaviors/quick5.c -rw-r--r-- 883 bytes
2414e6b2Zach DeCook Documentation: Add man pages in scdoc format 3 months ago
                                                                                
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
46
47
48
49
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#include <string.h>

#define BUFSIZE 1024
char wordBuff[BUFSIZE];

// fgets, but without the newline/tab.
char *fgetst(char *restrict s, int size, FILE *restrict stream) {
	char *r = fgets(s, size, stream);
	if (r) {
		char * sp = s;
		for(; sp[0] != '\0'; sp++) {
			if (sp[0] == '\n' || sp[0] == '\t') {
				sp[0] = '\0';
			}
		}
	}
	return r;
}

bool strdif(char* a, char* b) {
	for (;a[0];) {
		if (tolower(a[0]) != tolower(b[0])){
			return true;
		}
		a++;
		b++;
		if (!b[0])return true;
	}
	return false;
}

int main(int argc, char **argv) {
	if(argc!=2)return 1;
	int found = 0;
	size_t len = strlen(argv[1]);

	while (found < 5 && fgetst(wordBuff, BUFSIZE, stdin)) {
		if (!strdif(argv[1], wordBuff)) {
			if (found > 0) printf("\t");
			printf("%s", wordBuff+len);
			found++;
		}
	}
	printf("\n");
	return 0;
}