473,386 Members | 1,828 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,386 software developers and data experts.

changing char value

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
4 1685

"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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Connie Sawyer | last post by:
I am trying to run the following query: ALTER TABLE dnb_profile ALTER COLUMN datetime and I keep getting the following error: Server: Msg 242, Level 16, State 3, Line 1 The conversion of...
2
by: der | last post by:
Hello all, I've a question about functions that takes as an argument a void *, and change its content. e.g, meset(void *s, int c, size_t n); Why does it work? The only solution I can think of...
2
by: mohan | last post by:
According to page 20 & 21 "Unix Network Proramming" W>Richard Stevens the vale of argv and argc are in initialized read-only data. This must mean that this is not changable inside the program (...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
4
by: Pokerkook | last post by:
Hello, If anybody could help me with this I would greatly appreciate it. Or at least tell me why I get the output of this garbage: 49 49 10 49 52
6
by: Ioannis Demetriades | last post by:
Hi, I need to change the printer's font to "control" -a printer font, and then send a sequence of characters to the printer. My problem is that I cannot change the printer's font. Can this be...
16
by: DaTurk | last post by:
Hi, I have a c# application that needs to access c++ libraries, so it does this by using a managed layer of c++ CLI. Anyway, in the CLI function call, that calls the unmanaged function it...
4
by: yaru22 | last post by:
Hi, I'm relatively new to C programming and was quite confused by this error. What I tried to do is that if I have a string with double quotes around it (i.e. char *str = "\"hello\"";), I have...
9
by: sarajan82 | last post by:
Hi All, I have a string represented by char* (I do not user string class): char *s="abcd"; Assume I want to remove the last two elements of s. What is the standard solution for this? Can I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.