Reputation: 11
I am going mental, boiled something down to simple, no matter how or what i try, an array will not work? whats up?
The code is simply a single cpp helloworld from cocos2dx. nothing more,
double *Array = new double[333];
if (Array == nullptr)
CCLOG("Error: memory could not be allocated");
//initialize it
for( int i = 0; i != 333; ++i){
Array[i] = 333 - i;
}
for( int i = 0; i != 333; ++i){
CCLOG("Hi %ld", Array[i] );
}
The loop always prints 0....
Ive tried many loops, test, the array is never array. its ALWAYS just an int, or double, or whatever type of array i try?
Any thoguhts?
VS2012 cocos2dx helloworld stripped to nothing but an array now. Windows 10
Upvotes: 0
Views: 396
Reputation: 11
the formatting was my mistake, i had not noticed to change it after trying, int, double, long, float etc.
The problem..went away after a reboot of my machine?
std::srray? How would this be used dynamically / resized?
Upvotes: 0
Reputation: 148870
Because you are trying to display a double with %ld
format. %ld
should be used only for long. IMHO you should :
either convert Array[i]
to a long :
CCLOG("Hi %ld", (long) Array[i] );
or use %g
format :
CCLOG("Hi %g", Array[i] );
Both methods should give you correct display.
Upvotes: 6