Thanks it worked. There was no prbolem. bye
Getting ASCII value from a variable
Collapse
X
-
Originally posted by AlienHi,
I am having some problems with getting the ASCII values. Here is my problem:
Here is the code:
[CODE="cpp"]void conv(int num[], char caracter[])
{
int i;
for(i = 0; i < strlen(characte r); i++)
{
char temp = character[i];
num[i] = temp - '0';
}
}[/CODE]
What I want to do is get the ASCII value of character[i] and store it into the char variable temp. And use subtract the temp from '0' which is 48.
So basically if I have one of the element in character[i] as 7, I want the temp to include ASCII equivalent of 7, not the actual number, So i can store in num[i].
However when I run the program, what it does is subtract the actual number i entered say 7, not its ascii equivalent 55 which i want.
Any help would be appreciated. Thanks.
This is normal.
You can almost operate with char as int that has value in range of -128 to 127.
You are supposed to add '0' to the actual value,not subtract it.
Also please use codetags
To open them use [CODE] and to close them use [\\CODE]
You can also specify language [CODE="cpp"]...
ps:I added another \ because this would actually close tag.
Savage
Comment