// Copyright 2013 Calvin Morrison #include #include #include #include int main(int argc, char **argv) { char *line = NULL; size_t len = 0; ssize_t read; if(argc != 2) { printf("Please supply a filename, and only a filename\n"); exit(EXIT_FAILURE); } FILE *fh = fopen(argv[1], "r" ); if(fh == NULL) { fprintf(stderr, "Couldn't open: %s\n", argv[1]); exit(EXIT_FAILURE); } unsigned long long counts[256] = {0}; while ((read = getline(&line, &len, fh)) != -1) { if(line[0] != '>') { unsigned int i = 0; for(i = 0; i < strlen(line); i++) { counts[line[i]]++; } } } free(line); printf("A:%llu\nC:%llu\nG:%llu\nT:%llu\n", counts['a'] + counts['A'], counts['c'] + counts['C'], counts['g'] + counts['G'], counts['t'] + counts['T']); return EXIT_SUCCESS; }