Char to Char *?

Is there a way to convert a Char to a Char *?
You can use the address-of operator (&). But I think there is probably more to the problem you are trying to fix then that...
closed account (3pj6b7Xj)
Convert a regular char to a pointer to type char? Sure just specify the address of the char with the & operator.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void letter(char * letter)
{
*letter = 'a';
}

int main()
{
char myletter = 'b';
letter(myletter); // compiler will complain because the function is expecting a pointer to type char.

// you can conver the char to char * by doing this...

letter(&myletter); // the & indicates you are passing the address of myletter which is what a pointer is designed to do, now the function will work and the compiler will keep his mouth shut.

}


hope it helps?
Last edited on
Topic archived. No new replies allowed.