Hi, I'm hoping someone might be able to help me with what I think might be a simple problem.
I have came across the need to add to an unsigned char array a literal single quote "'"

My question is how can I achieve that?

unsigned char uArray[4];
uArray[0] = 'I';
uArray[1] = 't';
uArray[2] = '''; // here is where my problem lies
uArray[3] = 's';

The quote I need to insert, is closing the opening quote.

I appreciate any help offered.


Sorry if you wasted time reading this, I found solution.
I guess sometimes I need to write a question down before the answewr comes to me.

uArray[2] = 39;

Thank you.

It's good that you found something that worked. However, you may be interested in finding out more about escape sequences, which allow you to use:

uArray[2] = '\''; // single quote + backslash + single quote + single quote

There are others, besides this one for the single quotation mark, such as:

\" for double quotation mark
\? for question mark
and a double backslash to represent the backslash

One of the most common that people come across is \n for newline, perhaps not realising that it belongs to a group of such escape sequences. A quick search on Google with give you a list of them.

Of course, I'm such a dimwit at times :(

I even used the escape to add a terminator '\0'.


Thanks for the heads up.

Of course, I'm such a dimwit at times :(

Who isn't? No worries.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.