C Programming Tutorial 26 - ASCII and Int Conversion

submitted by mkenny400 on 03/19/18 1

In the last two videos I've laid the foundation for understanding character data and integer data. Be sure to check those out.   In this video we are going to be writing a program that will take a character and convert it to an integer.   First, we will cover how to convert from ASCII to an integer. Then, we will convert it back.   The next thing we will do is show that you can do math with characters. That's because they're really just numbers in disguise.   #include (less than sign) stdio.h (great than sign) int main() { char ASCII; printf("Please enter a character: "); scanf("%c", &ASCII); printf("The int value of your character is: %d\n", ASCII); int integer; printf("Please enter an integer between 0 and 127: "); scanf("%d", &integer); printf("The ASCII for that int is: %c\n\n", integer); return 0; } Now, let's try to do some math with characters:   //Math with ASCII: char mathz = 'A' + '\t'; printf("A(65) + \t(11) = %c(%d)\n", mathz, mathz);   You can see that the \t is actually rendered. Remember how if we want to go to a newline we use \n, well we can also use \t! To actually print a backslash we need to use two back slashes.   //Math with ASCII: char mathz = 'A' + '\t'; printf("A(65) + \\t(11) = %c(%d)\n", mathz, mathz); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! www.patreon.com/calebcurry Subscribe to my newsletter: eepurl.com/-8qtH Donate!: bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: CalebCurry.com Facebook: www.facebook.com/CalebTheVideoMaker Google+: plus.google.com/+CalebTheVideoMaker2 Twitter: twitter.com/calebCurry Amazing Web Hosting - www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)

Leave a comment

Be the first to comment

Collections with this video
Email
Message
×
Embed video on a website or blog
Width
px
Height
px
×
Join Huzzaz
Start collecting all your favorite videos
×
Log in
Join Huzzaz

facebook login
×
Retrieve username and password
Name
Enter your email address to retrieve your username and password
(Check your spam folder if you don't find it in your inbox)

×