I finally wrote something with a purpose! This program takes a three letter codon and tells the user the amino acid that the codon will make. My next goal is create a program that can take a continuous stream of codons and print out the corresponding amino acid chain.
Anyway, this is my first useful program (prior to five days ago I had zero programming experiences), so I'm quite proud of myself. Nonetheless I know it must look cumbersome to the seasoned programmer, and I'm quite certain the same result could probably be achieved using more advanced coding techniques. Any suggestions are welcome, as well as things I should be thinking about as I continue to my journey learning the C programming language!
Code:
//
// main.c
// PageA2
// Created by Phoebe August 31, 2012
//
// A program to determine the amino acid from a three letter codon
#include <stdio.h>
#include <string.h>
char amino_acids[][40] = {
"GCU GCC GCA GCG Ala",
"CGU CGC CGA CGG AGA AGG Arg",
"AAU AAC Asn",
"GAU GAC Asp",
"UGU UGC Cys",
"CAA CAG Gln",
"GAA GAG Glu",
"GGU GGC GGA GGG Gly",
"CAU CAC His",
"AUU AUC AUA Ile",
"AUG START/MET",
"UUA UUG CUU CUC CUA CUG Leu",
"AAA AAG Lys",
"UUU UUC Phe",
"CCU CCC CCA CCG Pro",
"UCU UCC UCA UCG AGU AGC Ser",
"ACU ACC ACA ACG Thr",
"UGG Trp",
"UAU UAC Tyr",
"GUU GUC GUA GUG Val",
"UAA UGA UAG STOP",
};
void find_amino_acid(char search_for[]){
int i;
for (i = 0 ; i < 21 ; i ++){
if(strstr(amino_acids[i], search_for))
printf("Amino Acid: '%s'", amino_acids[i]+24);
}
}
int main()
{
char search_for[4];
printf("Enter a three letter codon in ALL CAPS: ");
fgets(search_for, 4, stdin);
char *test = strchr(search_for, '\n');
if (test!=0) *test='\0';
find_amino_acid(search_for);
return 0;
}