diff --git a/gene.txt b/gene.txt index 1eab733..e2aab64 100644 --- a/gene.txt +++ b/gene.txt @@ -1,3 +1,4 @@ # gene w ABC 1.0 -DED 2.0 \ No newline at end of file +DED 2.0 +DAD 8.0 \ No newline at end of file diff --git a/main.c b/main.c index 63aca10..a74fcc0 100644 --- a/main.c +++ b/main.c @@ -26,6 +26,7 @@ #include #include +#include #define MAX_LINE_LENGTH 1000 int main() { @@ -40,13 +41,19 @@ int main() { exit(1); } + double sum = 0.0; while (fgets(line, MAX_LINE_LENGTH, fptr)!=NULL) { - printf("%s", line); +// printf("%s", line); char gene[MAX_LINE_LENGTH]; double weight; - sscanf(line,"%s %f", gene, &weight); + sscanf(line,"%s %lf", gene, &weight); - printf("\nGene: %s has weight %lf\n", gene, weight); + if (strchr(gene, 'A') != NULL) { + printf("\nGene A: %s has weight %lf\n", gene, weight); + sum += weight; + } } + + printf("Total sum for gene A is %lf\n", sum); } \ No newline at end of file