-1

http://code.tutsplus.com/tutorials/ios-sdk-advanced-freehand-drawing-techniques--mobile-15602

In this tutorial I found a line that made me wonder

CGPoint pointsBuffer[CAPACITY];

where CAPACITY is

#define CAPACITY 100

I tried to NSLog pointsBuffer, but it seems I can't, can anyone explain this to me? and how does this useful to the code? Thanks!

jane
  • 309
  • 2
  • 11

3 Answers3

1

If you want to print all the values, you'll need to iterate over the whole array:

for (size_t i = 0; i < CAPACITY; i++)
    NSLog(@"Point %zu = (%f, %f)", i, pointsBuffer[i].x pointsBuffer[i].y);

How is it useful to the code? The tutorial explains it in Step 2.

dreamlax
  • 93,976
  • 29
  • 161
  • 209
1

Its an array of CGPoint and you want is something like this:

for (int capacityIndex = 0; capacityIndex < CAPACITY; capacityIndex++) {
    NSLog(@"%@", NSStringFromCGPoint(pointsBuffer[capacityIndex]));
}

Or to print a specific point:

NSLog(@"%@", NSStringFromCGPoint(pointsBuffer[5])); // To print 6th point.
Abhinav
  • 37,684
  • 43
  • 191
  • 309
-1

This an array of 100 points.

you can NSLog

if you don't assign point in an array index, it will return x=0, y=0 as default point value

NSLog(@"point(%f,%f)",pointsBuffer[0].x,pointsBuffer[0].y);

you can assign value into array index

pointsBuffer[1].x = 120.0;
pointsBuffer[1].x = 130.0;
NSLog(@"point(%f,%f)",pointsBuffer[1].x,pointsBuffer[1].y);
Jamil
  • 2,977
  • 1
  • 13
  • 23