-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcomp.c
40 lines (40 loc) · 780 Bytes
/
rcomp.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
int c;
char *s, *dna;
char *t;
if (argc != 2) {
fprintf(stderr, "syntax: rcomp GATTACA\n");
exit(1);
}
dna = argv[1];
t = strdup(dna);*t++ = '\0';
s = dna;
while (*s != '\0') { // complement
c = *s++;
if (c == 'A' || c == 'a') {
c = 'T';
} else if (c == 'T' || c == 't') {
c = 'A';
} else if (c == 'G' || c == 'g') {
c = 'C';
} else if (c == 'C' || c == 'c') {
c = 'G';
} else {
fprintf(stderr, "rcomp: expected one of [ACGT] at %s\n", --s);
exit(1);
}
*t++ = c;
}
for (;;) { // reverse
c = *--t;
if (c == '\0') break;
putchar(c);
}
putchar('\n');
exit(0);
return 0;
}