9 years, 3 months ago.

How to get ASCII null?

Hi,

How can I get an ASCII null character in the mbed compiler? Currently, in MAC, by typing %00 I can achieve a NUL character. However, when I try the same methodology in mbed compiler [by typing "%00"] I do not achieve the right results.

Is there a way to achieve the right ASCII Null?

3 Answers

9 years, 3 months ago.

You get the Ascii null using: '\0'.However this is identical to just 0, 0x00, etc, since the Ascii null is, not completely accidental, equal to zero.

Accepted Answer

Thank you, I needed an ASCII null in the code

posted by Majed Shakir 21 Aug 2015
9 years, 3 months ago.

you can use

pc.putc(0x00);

or

pc.printf("show %c", 0x00);

Thank you, However, I do need it to be in ASCII character in the compiler since the code is expecting an ascii character

posted by Majed Shakir 20 Aug 2015

Not sure I understand what you mean. ASCII chars are just values between 0x00 and 0xFF. Anyhow, you can convert or typecast them to make the compiler happy.

pc.printf("show %c", (char)  0x00);
posted by Wim Huiskamp 21 Aug 2015

Thank you friend for the help

posted by Majed Shakir 21 Aug 2015
9 years, 3 months ago.

A variable containing zeros can be used in multiple ways, maybe a char array is what you are looking for:

unsigned char c[] = { 'A', 'B', 'C', 0, 0, 0 }; int sz = sizeof(c);

With the size sz=6 you will see that it is 6 bytes long. I would recommend to get a C/C++ Basic book to learn C/C++.

Thank you you have given me a good idea

posted by Majed Shakir 21 Aug 2015