There's a couple of fundamental flaws here. The type int is generally 32 bits wide meaning it can only hold numbers up to 2^32 (2^31 if it's a signed int). An int isn't always 32 bits wide. It's not actually guaranteed to be anything (except for in relation to other types). Common sizes in use today are 16 bits, 32 bits, and 64 bits. Anyway, your compiler is probably using 32-bit ints. A 20 digit number is far larger than this. This is what is referred to as an "overflow". So that's one thing you're going to want to keep in mind and check when writing this thing.
I'm also not quite sure about adding together 2 numbers from 2 arrays. You want to add all 4 numbers together?
Anyway, here's a program that will read 2 sets of 2 numbers in from a text file and store them in 2 arrays for you:
Code:
$ cat foo.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
int array1[2];
int array2[2];
char buf[128];
fp = fopen("mydata.txt", "r");
if(fp == NULL)
{
puts("Cannot open file for reading");
exit(EXIT_FAILURE);
}
fgets(buf, sizeof(buf), fp);
sscanf(buf, "%d %d", &array1[0], &array1[1]);
fgets(buf, sizeof(buf), fp);
sscanf(buf, "%d %d", &array2[0], &array2[1]);
fclose(fp);
printf("Set 1 - 1st: %d, 2nd: %d\n", array1[0], array1[1]);
printf("Set 2 - 1st: %d, 2nd: %d\n", array2[0], array2[1]);
return 0;
}
Here's the contents of mydata.txt:
And here's the results of running the program:
$ ./foo
Set 1 - 1st: 724982, 2nd: 29384
Set 2 - 1st: 2934, 2nd: 29840
If you have specific questions I'll be happy to answer them.