HDdeveloper
HDdeveloper

Reputation: 4404

Converting UITextField ( field.text) NSString * to char *?

I want to convert the NSString* str to char* ch, for using it as parameter in this function: str is obtained from UITextField's text.

void CUserSession::Login (char *pUsername, char *pPassword)

Please help.

On using

ch = [str UTF8String];

//I am getting this error.

Cannot initialize a parameter of type 'char *' with an rvalue of type 'const char *'

then On Using

ch = (const uint8_t *)[str UTF8String];

//I am getting this error.

Cannot initialize a parameter of type 'char *' with an rvalue of type 'const uint8_t *' (aka 'const unsigned char *')

Upvotes: 0

Views: 857

Answers (2)

Midhun MP
Midhun MP

Reputation: 107121

Replace it

ch = [str UTF8String];

with

const char *ch = [str UTF8String];

or try with:

ch = (char *)[str UTF8String];

Upvotes: 3

user529758
user529758

Reputation:

Why don't you try the obvious solution? Declare the pointer correctly:

const char *ch = [str UTF8String];

Upvotes: 1

Related Questions