C Programming Tutorial 25 – Char Data Type

Don’t forget to read the last blog on ASCII! Are you new here? Start at the beginning, Intro to C!

We can create a char variable like this:

It is very important that we use single quotes.

That’s really all there is to creating a char variable, so now let’s talk printing this to the console and getting it from user input.

We are going to need to learn a new format character, specifically %c. This tells the function that we are going to be working with char data.

Now, if we actually wanted to scan the data from the console, we can use scanf():

If you want to know more about ASCII, check out http://www.asciitable.com/

The first section on the ASCII table are called control characters and only a few are going to be useful to us. I’d also group the last one in here, which is the DEL ASCII code. These codes were for controlling devices, such as printers. Some are still going to be useful to us, such as the new line character.

The rest of the standard table are called printable characters. These are the characters that you can visually see. You can also see that each character has an associated integer value, 0-127.

The second table represents the extended ASCII, which gives more available options.

In the next video we are going to create a program that will convert between int and ASCII. By the end of that video, you’ll see how easy working with ASCII is.

Are you ready to learn more? Learn about ASCII and Int Conversion in the next blog!

Leave a Reply

Your email address will not be published. Required fields are marked *