changing char value

M

muser

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;
 
J

jeffc

muser said:
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;
}
 
U

Unforgiven

muser said:
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.
 
D

Default User

Unforgiven said:
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
 
R

Ron Natalie

Default User said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

function error 6
Access violation error 10
Reading a file 1
Char array as a function returned value 2
Reading a file. 3
unions 2
Short program 3
The program/ header file contents 2

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top