Question: I have the following in a text file called: values.txt

```
1 4 
2.5 3.76
122 10
277.543 
165.4432

```

I am trying to read the content of this text file, and add each two pairs together and output the result ...
the output would be something like this :

```
1 Pair:(1, 4) = 5

2 Pair:(2.5, 3.76)= 6.26

```

and so on ..

I am opening the file like this 

```
int c;
FILE myfile; 

myfile= fopen("values.txt", "r"); 
if ( myfile == NULL ) { 
  printf("Cannot open TEXT file\n");
  return 1; 
}

double aa,bb;
while ( (c = getc(myfile) ) != EOF ) { 
    // HERE SHOULD I DO THE OUTPUT BUT HOW?
}

```

Any help is really appreciated ..

Language = C

Answer: 
The following code does what you expect. myfile should be declared as FILE\*. fopen returns a pointer to FILE structure. If the file is very large, I would recommend reading in buffers of big size (eg: 65535 etc) and parse it char by char and convert it to float values. It reduces system call overhead which takes more time than processing text to float values.

```
#include <stdio.h>
#include <string.h>

main(int argc, char *argv[])
{
    FILE* myfile; 

    myfile = fopen("values.txt", "r"); 
    if ( myfile == NULL ) { 
        printf("Cannot open TEXT file\n");
        return 1; 
    }

    double aa,bb;
    while (2 == fscanf(myfile, "%lf %lf", &aa, &bb)) {
        printf("%lf\n", aa+bb);
    }
    return 0;
}

```
For this simple task, use 
```
double a, b;
if (fscanf(myfile, "%lf %lf", &a, &b) == 2)
        printf("%f + %f = %f\n", a, b, a+b);
```
.