'Adding sum;'

This commit is contained in:
Arkadiusz Hypki 2023-03-24 11:13:24 +01:00
parent 7fcaa90b13
commit b9fa899970
2 changed files with 12 additions and 4 deletions

View File

@ -1,3 +1,4 @@
# gene w
ABC 1.0
DED 2.0
DED 2.0
DAD 8.0

13
main.c
View File

@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}