masaldana2 masaldana2 - 4 months ago 14
Objective-C Question

How to print full array inside a block or outside block?

Hello I have an array of floats, but I just can't print the full array

here's the first block which saves successfully the floats into the array floatDataArray

double valuesArray[882000];
double *floatDataArray = valuesArray;
__block int j = 0;
//sampleInfo.size = 0;
[AEAudioFileReader readFileAtURL:amen.url targetAudioDescription:desc readBlock: ^(const AudioBufferList *buffer,UInt32(mBufferBlock)){

AudioBuffer audioBuffer = buffer->mBuffers[0];

float *samplesAsCArray = (float *)audioBuffer.mData;
printf("\n%i", buffer->mBuffers[1]);
for (int i = 0; i<mBufferBlock; i++) {
floatDataArray[j] = (double)samplesAsCArray[i] ; //PUT YOUR DATA INTO FLOAT ARRAY
// printf("\n%f",floatDataArray[j]); //PRINT YOUR ARRAY'S DATA IN FLOAT FORM RANGING -1 TO +1


Then the completion block where it goes thru all the buffers first

} completionBlock:^(NSError* error){

printf("\n%@",floatDataArray); //Print full array


which I'm able to print single values such as floatDataArray[0] but not the full one it sends nothing using %@, %s


If you want to print a C array of floats you will need to write a function to do so. You can't use printf or NSLog to print a C array without writing a for loop

If you were to uncomment the printf line in your top block of code you'd see your array. However, if you really have 882,000 entries in the array printing them all to the console will take a LOOOOOOOOOOOOONG time, and not be very useful.

for (int i = 0; i<mBufferBlock; i++) {
    printf("\n%f", floatDataArray[i]

You might want to limit the output to a fixed number of digits to make the output file smaller. If you use 6 digits of precision:

for (int i = 0; i<mBufferBlock; i++) {
    printf("\n%06f", floatDataArray[i]

Then you'll have 9 bytes of output for values <10, plus another byte/value for each extra integer digit in your value (1000.000001 would take 12 bytes, including the carriage return at the end.) If all the output takes 12 bytes, that means your output log file would be about 10.5 mb. That's a LOT of text.