Skip to content

RNA Transcription

Intro

Both DNA and RNA strands are a sequence of nucleotides.

The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T).

The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U).

Task

Given a DNA strand, return its RNA complement (per RNA transcription).

Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:

  • G -> C
  • C -> G
  • T -> A
  • A -> U

The Code

 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
#include "rna_transcription.h"
#include "stdlib.h"
#include "string.h"

char *to_rna(const char *dna) {
  static char *var;
  var = malloc(strlen(dna));
  memset(var, 0, strlen(dna));
  int i = 0;
  for (i = 0; i < (int)strlen(dna); i++) {
    char *var01 = 0;
    switch (dna[i]) {
    case 'C':
      var01 = "G";
      break;
    case 'G':
      var01 = "C";
      break;
    case 'T':
      var01 = "A";
      break;
    case 'A':
      var01 = "U";
      break;
    }
    strcat(var, var01);
  }

  return var;
}
1
2
3
4
5
6
#ifndef RNA_TRANSCRIPTION_H
#define RNA_TRANSCRIPTION_H

char *to_rna(const char *dna);

#endif

Last update: February 8, 2021

Comments