I'm writing a program that reads text from a text file into a c-string and then convert the ascii character to integer. I already did the reverse process. integer>ascii. How do I do ascii>integer
1 2 3 4 5 6 7
int DecodeInt(char c) // this function just outputs the integer 97
{
c = 'a';
int a = c;
return a;
}
I'm writing a program that reads text from a text file into a c-string and then convert the ascii character to integer. I already did the reverse process. integer>ascii. How do I do ascii>integer
1 2 3 4 5 6 7
int DecodeInt(char c) // this function just outputs the integer 97
{
c = 'a';
int a = c;
return a;
}
You need no a special function to convert an object of type char to int because char is already an integral type. All what you need is to assign a char object to an int object or use casting. For example
char c = 'a';
std::cout << a << std::endl; // output is a
std::cout << ( int )a << std::endl; // output is 97
int i = c;
std::cout << a << std::endl; // output is a
std::cout << i << std::endl; // output is 97