C: nucleotide-count & rna-transcription

This commit is contained in:
2021-08-11 20:57:57 +02:00
parent 2342d9b7f6
commit 9542b0bf09
10 changed files with 433 additions and 0 deletions

View 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

View 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