C: nucleotide-count & rna-transcription
This commit is contained in:
37
c/rna-transcription/src/rna_transcription.c
Normal file
37
c/rna-transcription/src/rna_transcription.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include "rna_transcription.h"
|
||||
|
||||
static char C[256]={
|
||||
['G']='C', ['C']='G', ['T']='A', ['A']='U',
|
||||
};
|
||||
|
||||
char *to_rna(const char *dna)
|
||||
{
|
||||
char *rna=malloc(strlen(dna+1)), *p;
|
||||
|
||||
if (rna) {
|
||||
for (p=rna; *dna; p++, dna++) {
|
||||
if (!(*p=C[(int)*dna])) {
|
||||
free(rna);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
*p=0;
|
||||
}
|
||||
return rna;
|
||||
}
|
||||
|
||||
/* See GNUmakefile below for explanation
|
||||
* https://github.com/braoult/exercism/blob/master/c/templates/GNUmakefile
|
||||
*/
|
||||
#ifdef UNIT_TEST
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int arg=1;
|
||||
|
||||
for (; arg<ac; ++arg) {
|
||||
printf("rna(%s)=%s\n", av[arg], to_rna(av[arg]));
|
||||
}
|
||||
}
|
||||
#endif
|
18
c/rna-transcription/src/rna_transcription.h
Normal file
18
c/rna-transcription/src/rna_transcription.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef RNA_TRANSCRIPTION_H
|
||||
#define RNA_TRANSCRIPTION_H
|
||||
|
||||
char *to_rna(const char *dna);
|
||||
|
||||
/* See GNUmakefile below for explanation
|
||||
* https://github.com/braoult/exercism/blob/master/c/templates/GNUmakefile
|
||||
*/
|
||||
#if defined UNIT_TEST || defined DEBUG
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef TESTALL
|
||||
#undef TEST_IGNORE
|
||||
#define TEST_IGNORE() {}
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user