Skip to content
Newer
Older
100644 56 lines (42 sloc) 872 Bytes
3f664ca cf_append:
mjd authored
1
2 #include "cf.h"
3 #include "cf_between.h"
4 #include "cf_rat.h"
5 #include <stdio.h>
6 #include <unistd.h>
78c874b missing declarations and other cleanups
Mark Dominus authored
7 #include <stdlib.h>
3f664ca cf_append:
mjd authored
8
9 void usage(char *argv0) {
10 fprintf(stderr, "Usage: %s a/b c/d\n\tFind simplest fraction between a/b and c/d\n", argv0);
bde7237 @mjdominus note that "between" utility is unimplemented
authored
11 fprintf(stderr, "(unimplemented)\n");
3f664ca cf_append:
mjd authored
12 exit(0);
13 }
14
15 unsigned parserat(char *s, int *n, int *d) {
16 *n = atoi(s);
17
18 while (*s != '\0' && *s != '/') s++;
19
20 if (*s == '\0') {
21 *d = 1;
22 return 1;
23 }
24
25 s++;
26 *d = atoi(s);
27
28 return 1;
29 }
30
31 int main(int argc, char **argv) {
32 char *prog = argv[0];
33 char **arg = argv+1;
34 int n, d;
35 CF a[2], r;
36
37 if (argc < 2) usage(prog);
38
39 {
40 unsigned i;
41 for (i=0; i<2; i++)
42 if (parserat(arg[i], &n, &d))
43 a[i] = new_rat(n, d);
44 else
45 usage(prog);
46 }
bde7237 @mjdominus note that "between" utility is unimplemented
authored
47 fprintf(stderr, "unimplemented\n");
48 return 19;
3f664ca cf_append:
mjd authored
49
50 r = between(a[0], a[1]);
51 print_cf(r);
52
53 return 0;
54 }
55
Something went wrong with that request. Please try again.