reading integers into arrays from text files
hi, am just starting to learn the c language and have just come accross arrays; im designing a program that will read integers from a text file then hold the values into arrays and finaly add them together, the numbers in the text file will be up to 20 digits long but they may be less and two sets of digits will be on the same line e.g the text file could look like this:
1234567 123456789101112
1234567898745 12545877
the first set of nubers on the top line would be read into the first array then the second set after the space would be read in to the the second array then the values would be added together in a 3rd array and printed on the screen, this process would then start again on the second set of numbers and do the same untill there arnt any more numbers in the text file,
so far i have made a loop that will read the first set of numbers into the first array:
( i=0; i<20; i++)
{
if ( i == " ")
break;
}
this should read the first numbers in and terminate when it reaches 20 digits or the space, but thats as far as i have got, i dont know if this will actually work and am not sure how to make a loop to read the second set of numbers and then how to get them to add up snd print out, I would be very gratful the books I have only show how to read text in so i am a bit stuck
thanks for reading
this is everything i have so far:
#include <stdio.h>
main ()
{
int *inf_ptr;
int array1[20];
int array2[20];
int array2[20];
int i;
infptr = fopen("mydata.txt", "r");
if (infptr==NULL)
{
printf(" cannot open file for reading");
}
else
{ for (i=0; i<20; i++)
{
if ( i == " ")
break;
}
return 0;
}