aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README1
-rwxr-xr-xcount_nucleobases.c19
2 files changed, 13 insertions, 7 deletions
diff --git a/README b/README
index 83f27d2..df12920 100644
--- a/README
+++ b/README
@@ -3,4 +3,3 @@ random fasta tools:
count_nucleobases - counts nucleobases (A, C, G, T) in fasta files
sequence_lengths - print out length of each sequences
sequence_end_points - print out the end position of each sequence (continuous)
-
diff --git a/count_nucleobases.c b/count_nucleobases.c
index 8c05a07..d4dca06 100755
--- a/count_nucleobases.c
+++ b/count_nucleobases.c
@@ -4,10 +4,10 @@
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
+#include <errno.h>
int main() {
- ssize_t len = 0;
-
+ size_t len = 0;
unsigned long long counts[256] = {0};
char buffer[4096];
@@ -15,10 +15,10 @@ int main() {
len = fread(&buffer, 1, 1, stdin);
- if(len != NULL) {
+ if(errno) {
if(buffer[0] == '>') {
header = true;
- while((len = fread(&buffer, 1, 4096, stdin)) != NULL) {
+ while((len = fread(&buffer, 1, 4096, stdin)) != 0) {
unsigned int i = 0;
for(i = 0; i < len; i++) {
if(buffer[i] == '>') {
@@ -32,8 +32,15 @@ int main() {
}
}
}
- } else { fprintf(stderr, "this does not look like a fasta file\n"); }
- } else { fprintf(stderr, "could not read file\n"); }
+ }
+ else {
+ fprintf(stderr, "this does not look like a fasta file\n");
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ fprintf(stderr, "could not read file\n");
+ exit(EXIT_FAILURE);
+ }
printf("A:%llu\nC:%llu\nG:%llu\nT:%llu\n",
counts['a'] + counts['A'],