So lets say I have an array, int array[3] = {123, 456, 789}.
If I wanted to take the first number of each value of the array and store it in another array, say int first[3];, how would I do that? I tried using a pointer to read the first memory address of each value of the array but it keeps returning the full array.
Name:
Anonymous2012-11-12 22:01
you are a faggot
Name:
Anonymous2012-11-12 22:02
I think what you want, is an array {1, 4, 7}? If so, you'll have to do some shit with the modulus operator. %
So you'd say for this shit
int first[3] = {0, 0, 0};
for(int i = 0; i < 3; i++) {
first[i] = array[i] % 100;
}
int main(void)
{
int numbers[] {1,2,3,4,5,6,7,8,9,0,12,34,56,78,90,123,456,789};
int first[sizeof(numbers)/sizeof(*numbers)] {0};
auto ptr = first;
auto get_first = [&ptr](int val) { unsigned int n = 10;
while (val/n) n*=10;
*ptr++ = val/(n/10); };
std::for_each(std::begin(array), std::end(array), get_first);