473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Getting ASCII value from a variable

61
Thanks it worked. There was no prbolem. bye
Sep 16 '07 #1
1 3471
Savage
1,764 Expert 1GB
Hi,

I am having some problems with getting the ASCII values. Here is my problem:
Here is the code:

Expand|Select|Wrap|Line Numbers
  1. void conv(int num[], char caracter[])
  2. {
  3.    int i;
  4.    for(i = 0; i < strlen(character); i++)
  5.    {
  6.       char temp = character[i];
  7.       num[i] = temp - '0';
  8.    }
  9. }
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
Sep 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Steve Horsley | last post by:
How can I get the ASCII value of a character, e.g. I have: str = "A B" for index in range(0, len(str)): value = WHAT_GOES_HERE?(str) print value and I hope to get: 65
6
by: Haas | last post by:
Hello folks, I just started a C++ course. An exercise is to give the ASCII value of a character read from keyboard. I place the input from the keyboard in a char-variable. How can i get the...
80
by: Bibby | last post by:
Hi, I'm interested in getting started in the programming world. I've dabbled in C, C++ and VB6. Which would be the best language to focus my attention to regarding the following considerations: ...
13
by: Randell D. | last post by:
Folks, I have two related questions: 1. I have seen unicode being mentioned in my javascript pocket book - is this the same as ascii codes? I think not though I'm not sure and I can't find...
1
by: James Dean | last post by:
i want to be able to get the correct ascii value from a byte without having to use the Convert.ToChar function as a char takes up two bytes of space and it is affecting the performance of my...
12
by: IamIan | last post by:
I searched the archives but couldn't find anyone else with this problem. Basically I'm grabbing all ASCII files in a directory and doing geoprocessing on them. I need to calculate a z-factor based...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
9
by: CapCity | last post by:
We're rewritting an app using C# 2005 and it needs to read files in netCDF format. A dll is available for this and we've had success in calling its functions, unless it updates strings. We have...
8
by: ianenis.tiryaki | last post by:
i couldnt figure out how i am supposed to find the ASCII code is there any way to do it? and main problem is i am not sure so i wanted to ask is it going to display 'a' ? am i right? What is...
3
by: bamboooxy | last post by:
Hi all, I am new to this forums and I am so happy if you guys can help me. I got the same problems with johell. The VB6 could not understand the extended ascii code , chr$(>128), it returns...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.