A c++ that converts char into ASCII number and vice versal. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

A c++ that converts char into ASCII number and vice versal.

i tried using int(word[1]) to convert character array into a number.

18th Jul 2018, 6:08 PM
Ezedin Ali
6 Answers
+ 2
Show your attempt, You need to prove that you tried to make the code.
18th Jul 2018, 6:13 PM
Manual
Manual - avatar
+ 2
i need a function that convert ascii number into symbols
19th Jul 2018, 7:09 PM
Ezedin Ali
0
Thats not c++ casting sintax. In c++ you cast like (int)word[1]
18th Jul 2018, 9:04 PM
Дмитро Іванов
Дмитро Іванов - avatar
0
In c++ you don't need a function for this. You don't even need to cast. E.g. if you have: int a = 'a'; the a variable will be 97 (ascii code for 'a'). and if you have: char b = 97; b will be 'a' You can even do some math with char. E.g. 'a'+1 will give you 98. Or 'b' if you cast like (char)('a'+1) Just check that out https://code.sololearn.com/cgPoe26gc2Pt/?ref=app
19th Jul 2018, 7:21 PM
Дмитро Іванов
Дмитро Іванов - avatar
0
there is a default value for each char. why u need to convert?
26th Jul 2018, 4:12 AM
Eyob Awoke
0
this is a code in java it gives u an idea******************* import java.util.Scanner; /** * Title: ASCII character codes viewer * Author: Igor Makarsky * Instruction: Enter a string and you will get codes of each char. */ public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String word = sc.nextLine(); char[] chars = word.toCharArray(); System.out.println("You entered: " + word); System.out.println("Here are ASCII character codes."); for(char c : chars) { System.out.printf("%c: %d\n", c, (int) c); } printTitle(); } private static void printTitle() { String title = "ASCII character codes viewer"; String border = ""; for(int i = 0; i < title.length(); i++) { border += (char) 205; } System.out.println((char) 201 + border + (char) 187); System.out.println((char) 186 + title + (char) 186); System.out.println((char) 200 + border + (char) 188); } }
26th Jul 2018, 4:48 AM
Eyob Awoke