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

char to short conversion

hello

i need the format for coverting a char to short one

can u hlp me
char c[2];
short myValue;
myValue= myValue + short(c);

that's the conversion i'm using

but thr is a error

Error 818: "char24t.h", line 44 # Type 'char *' is larger than type 'short', truncation in value may result.
myValue= myValue + short(c);


how can i modify this
Mar 30 '07 #1
2 13916
horace1
1,510 Expert 1GB
the name of an array is a pointer to its first element so
Expand|Select|Wrap|Line Numbers
  1.   myValue= myValue + short(c);
  2.  
you are trying to add a pointer to a short

what exactly do you wish to do, e.g.
Expand|Select|Wrap|Line Numbers
  1. myValue= myValue + c[0];
this adds the value of c[0] to myValue
Mar 30 '07 #2
Ganon11
3,652 Expert 2GB
But since c[0] is a character, you may get unexpected results from this, so you will still need the conversion:

Expand|Select|Wrap|Line Numbers
  1. myValue = myValue + short(c[0]);
should be what you need.
Mar 30 '07 #3

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

Similar topics

18
by: Charles Kerekes | last post by:
Hello everyone, I am still learning C++, so I'm not sure what I'm trying to do is possible. Her is a simplified example: char Test = 'L'; cout << "Test Char as decimal: " << dec << Test <<...
2
by: Abhijit Bhadra | last post by:
Hi , I was trying to build my project in VC with latest Service Packs but got this error . C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : error C2440: 'return' :...
32
by: Conan1st | last post by:
Hello everyone! I made a variable under unsigned short but displaying it using char the value that doesnt change in fact is shown changed... unsigned short a a = 321;
10
by: tinesan | last post by:
Hello fellow C programmers, I'm just learning to program with C, and I'm wondering what the difference between signed and unsigned char is. To me there seems to be no difference, and the...
4
by: jim_geissman | last post by:
I have data tables that include ZIP code, as char(5). The values look like integers, but they are padded with leading zeroes to fill out 5 characters, '00234'. There are SPs to look up data,...
19
by: Dancefire | last post by:
Hi, everyone It might be a simple question, but I really don't know the answer. char c = '1'; cout << c; The above code will only output a '1' rather than 0x31; If I use int cast, it can...
20
by: Junmin H. | last post by:
Hello, I am trying to print the range of unsigned char and unsigned int. The one for char is working good, gives me a correct output, however the other one for int doesnt, why?? Thanks #include...
17
by: spasmous | last post by:
I need a way to search through a block of memory for a char array "DA" using a pointer to a short. Ideally I would like to write something like: short *data = ... some data...; int j = 0;...
5
by: Neel | last post by:
Hi friends, How can I store a short into an unsigned char??? its like unsigned char msg; //now I want to assign 0xAB into it.
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.