i have a 2d array which contains numbers and characters loaded from a txt.
i declared the array like "string myarray[27][5]". It has a format like:
1 3 28 Steve Hole
2 1 29 Anthony Curtis
......
......
i need to sum the third collumn which means the minutes.
for(i=0;i<27;i++)
{
total += myarray[i][2];
}
cout<<total<<endl;
the main problem is that i can't convert string to int, anyway i tried atoi, atol but it didn't worked...
please help me out!
int string2int ( int string)
{
return string - 48;
}
------------------------------------------------------
int total; declaration is still there in mycode. :)
I don't really understand this "-48" stuff.
i could make my own atoi function, but how?
which part of the programm will solve me the problem to count the time,
and anyway convert the string array type to int array or int anything.
i'am not able to sum minutes beacause i must have to work with string array because of the txt, and its not allowing sum.
sum.
the character stored in each array of string is an ASCII character code which is a decimal number and it just so happens that 0 to 9 is 48 to 57 in ASCII
this tech only works on single digit numbers . to convert 234 from string to int you would have work out the length of the numbers and the sequence and then do the following calculation :
(100 * 2) + (10 * 3) + (4) = 234