wow thanks for that it help tremendously. The task was to add 100 50 digit numbers and display the first 10 digits of the answer. So i could test and for easy posting on here i just used the first 4 hence the #define N. this is the final solution.
Code:
#include <stdio.h>
#include <stdlib.h>
#define N 4
long unsigned int StringtoNum( char [] );
void DivideString( const char * [], char [], int, int, int );
int main()
{
//declare variables
const char *cNumbers[N] = {
"37107287533902102798797998220837590246510135740250",
"46376937677490009712648124896970078050417018260538",
"74324986199524741059474233309513058123726617309629",
"91942213363574161572522430563301811072406154908250",
};
int i, iNumCarry = 0, j = 50;
long unsigned int iDivide =10000000000, iFinalTotal = 0;
double tmpTotal = 0;
char cStrtoNum[11] = { '\0' };
do
{
j -= 10;
tmpTotal += iNumCarry;
if ( j > 0 )
{
for ( i = 0; i < N; i++ )
{
DivideString( cNumbers, cStrtoNum, i, j, j + 11 );
tmpTotal += StringtoNum( cStrtoNum );
}
iNumCarry = tmpTotal / iDivide;
printf("%lf %d\n", tmpTotal, iNumCarry);
tmpTotal = 0;
}
else
{
for ( i = 0; i < N; i++ )
{
DivideString( cNumbers, cStrtoNum, i, j, j + 11 );
tmpTotal += StringtoNum( cStrtoNum );
}
}
} while ( j > 0 );
iFinalTotal = tmpTotal / 100;
printf("%lu\n", iFinalTotal);
return 0;
}
long unsigned int StringtoNum( char strConvert[] )
{
long unsigned int iNumConverted = 0;
iNumConverted = strtoul( strConvert, NULL, 10 );
return iNumConverted;
}
void DivideString( const char *cData[], char strToConvert[], int i, int iLower, int iUpper)
{
//declare variable
int j;
for ( j = iLower; j < iUpper; j++ )
{
strToConvert[j - iLower] = cData[i][j];
}
}
once again as always thanks for the help