TheLearner
TheLearner

Reputation: 19507

Retrieve a char from a char array

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
}

Upvotes: 0

Views: 182

Answers (1)

Carl Norum
Carl Norum

Reputation: 225262

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.

Upvotes: 2

Related Questions