tags:

views:

35

answers:

1

Does anyone know how to retrieve a char value from a char array:

char* alphaChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

for (int rowIndex = 0; rowIndex < 12; rowIndex++) 
{
    char* text = (char*)alphaChars[0]; //this throws an error

    //CGContextShowTextAtPoint(context, 10, 15, text, strlen(text)); //This is where I wanna use it
}
+2  A: 

If you just want one character, you don't want to assign it to a pointer:

char text = alphaChars[0];

Then you would call your next function:

CGContextShowTextAtPoint(context, 10, 15, &text, 1);

If you want the whole string, which is sort of what your code looks like it's doing, you don't need to have an intermediate variable at all.

Carl Norum
Just out of interest: I didn't know you could pick and choose when to use pointers and when not to. I thought objects need points and types like int don't.
TheLearner
@TheLearner, you're right that in Objective-C you can't make a concrete instance of an object; only pointers to objects are allowed. I suggest you try an online C tutorial or something to get a better grasp on working with pointers.
Carl Norum