+ 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.
6 Respuestas
+ 2
Show your attempt, You need to prove that you tried to make the code.
+ 2
i need a function that convert ascii number into symbols
0
Thats not c++ casting sintax. In c++ you cast like (int)word[1]
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
0
there is a default value for each char. why u need to convert?
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);
}
}