0

Hello,

I am having trouble with a simple math operation after reading from a file.

If a particular condition is met, i am copying a number(7 positions), starting from position 31.

My aim is to sum all these numbers when the condition is met.

I am testing the code on a file where the condition is met only once, as follows:

```
ATOM 5616 N MET B 1 334.916 199.163 84.447 0.70172.02 N
```

And yet the ouput is double what it should be: 669.831970 (right answer: 334.916)

```
while(fgets(s, 80 , fp1)!=NULL)
{
if((s[13] == 'N' && s[24] == ' ' && s[25] == '1'))
{
strncpy (sx, s+31, 7);
sx[7] = '/0';
x = atof(sx);
sum = sum + x;
}
}
printf("%f", sum);
```

Thanks in advance

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting