By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

changing char value

P: n/a
struct crecord {
char customercode[6];
}

crecord Newcrecord;

char temp1;

strncpy( Newcrecord.customercode, &temp1[1], 5 )
etc

if I have to perform a mathmatical equation on customercode, how would
I go about it.

if char customercode contain
customercode[0] = 1;
customercode[1] = 2;

I was told that to find its correct integer value, I would have to
minus 1 by 48, to get the digit 1.
could someone give me a list of char digits and their corresponding
value
i.e.
1 = 49;
2 = 48;

And if possible the code to achieve this.
e.g. Newcrecord.customercode[0] = 49 - 48;
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"muser" <ch**********@hotmail.com> wrote in message
news:f9**************************@posting.google.c om...

I was told that to find its correct integer value, I would have to
minus 1 by 48, to get the digit 1.
could someone give me a list of char digits and their corresponding
value
i.e.
1 = 49;
2 = 48;

And if possible the code to achieve this.
e.g. Newcrecord.customercode[0] = 49 - 48;


It's different on different computers. If you're using ASCII, then that is
easily searched on the web. Anyway, just display the values:
int i;
char c;
for (i = 0; i < 256; ++i)
{
c = i;
cout << i << " " << c << endl;
}

For just the digits, the mirror of that is
char c;
int i;
for (c='0'; c <= '9'; ++c)
{
i = c;
cout << c << " " << i << endl;
}

Jul 22 '05 #2

P: n/a
muser wrote:
struct crecord {
char customercode[6];
}

crecord Newcrecord;

char temp1;

strncpy( Newcrecord.customercode, &temp1[1], 5 )
etc

if I have to perform a mathmatical equation on customercode, how would
I go about it.

if char customercode contain
customercode[0] = 1;
customercode[1] = 2;

I was told that to find its correct integer value, I would have to
minus 1 by 48, to get the digit 1.
could someone give me a list of char digits and their corresponding
value
i.e.
1 = 49;
2 = 48;

And if possible the code to achieve this.
e.g. Newcrecord.customercode[0] = 49 - 48;


You can actually just do this (assuming the numbers are laid out 0-9, as
they are in ASCII):
char ch = '3';
int n = ch - '0';

Now n will have the value 3.

--
Unforgiven

Jul 22 '05 #3

P: n/a
Unforgiven wrote:
You can actually just do this (assuming the numbers are laid out 0-9, as
they are in ASCII):

They are required to be that way by the Standard. The same is not true
for the alpha characters though.


Brian Rodenborn
Jul 22 '05 #4

P: n/a

"Default User" <fi********@boeing.com.invalid> wrote in message
news:3F***************@boeing.com.invalid...
Unforgiven wrote:
You can actually just do this (assuming the numbers are laid out 0-9, as
they are in ASCII):

They are required to be that way by the Standard. The same is not true
for the alpha characters though.


Yep, just remember Junior is 11.
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.