'Adding sum;'
This commit is contained in:
parent
7fcaa90b13
commit
b9fa899970
13
main.c
13
main.c
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#define MAX_LINE_LENGTH 1000
|
#define MAX_LINE_LENGTH 1000
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -40,13 +41,19 @@ int main() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double sum = 0.0;
|
||||||
while (fgets(line, MAX_LINE_LENGTH, fptr)!=NULL) {
|
while (fgets(line, MAX_LINE_LENGTH, fptr)!=NULL) {
|
||||||
printf("%s", line);
|
// printf("%s", line);
|
||||||
|
|
||||||
char gene[MAX_LINE_LENGTH];
|
char gene[MAX_LINE_LENGTH];
|
||||||
double weight;
|
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);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user