34 lines
703 B
C
34 lines
703 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define MAX_LINE_LENGTH 1000
|
|
|
|
int main() {
|
|
int num;
|
|
FILE *fptr;
|
|
char line[MAX_LINE_LENGTH];
|
|
|
|
fptr = fopen("../gene.txt", "r");
|
|
|
|
if (fptr == NULL) {
|
|
printf("File is empty!");
|
|
exit(1);
|
|
}
|
|
|
|
double sum = 0.0;
|
|
while (fgets(line, MAX_LINE_LENGTH, fptr)!=NULL) {
|
|
// printf("%s", line);
|
|
|
|
char gene[MAX_LINE_LENGTH];
|
|
double weight;
|
|
sscanf(line,"%s %lf", 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);
|
|
} |