-
Please help with ASCII
Is there a function to convert a character to its ASCII equivalent and assign it to a variable? or is there some other method..??
I know I can assign a character to an integer variable and get its ascii, but I can't do it with an input of a character variable.
Please help if you can. :confused:
-
I never heard about such a function, but this should do the trick:
Code:
int num1;
char num2='a';
num1 = num2;
now num1 holds the value: 97
also, read about printf(), %d, %c and how to use them!!!
-
You *might* try the function called atoi()...
But realistically, it's already a value. if you create a 'char' variable, and it the letter 'g' is input into it (or assigned by you, for that matter), your computer does _not_ remember 'g'... it remembers the ASCII value.
A char is a signed value from 0 to 127 (in ASCII). an unsigned char is a value from 0 to 255 (in ASCII), which is the maximum range an 8-bit value can hold.
-
Emphasis on *might*. The reason we say you might be able to use it is that atoi() doesn't take a character. It takes a string as an argument.
That being said, you cannot simply pass it a single character and expect it to work. You'll have to convert it to a string first.
Quzah.
-
What Devil Panther replied is called cast!
You can also turn it around: and the result is the character '"'.
klausi