473,785 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array Lookup [Was: Why is "Hello World" const char* ?]

Hello,

Thanks for all your response on my question about signed/unsigned chars.

The problem is this: I want to use the char array for a ArrayLookup, so
I need to convert char to unsigned int.

But this doesn't work!

If I try this:

#include <stdio.h>
int main() {
char c = -1; // 129 unsigned and -1 signed right?
// convert it to a value between 0 - 255 for array Lookup
unsigned int arrayIndex = (unsigned int) c;
if (arrayIndex < 0)
printf("ArrayIn dex still negative after conversion to unsigned int
%d\n",arrayInde x);
else
printf("Unsigne d representation is OK for ArrayIndex=%d\n ",arrayInde x);
}

The output is: "ArrayIndex still negative after conversion to unsigned
int -1"

How is this possible?

I would expect a output 129.

Thanks!

Hans
Jul 23 '05
13 2505
"TTroy" <ti*****@gmail. com> writes:
[...]
I don't think Mike meant the OP was truly lying for the purpose of
confusing c.l.c readers. He probably meant it as if he was suprised,
kind of like if someone says something unbelievable you might respond:
"No way, you're lying."

He did further go on to help the OP, so lighten up Keith. If you're
going to be such a hard a*s about every post on c.l.c. that is even a
little OT, incorrect or improper, then lead by example.
Read Mike's reaponse (which you probably hadn't seen when you posted
yours).
In the thread titled: "Do you like my strlcpy strlcat etc?" you join in
with other posters to mock the use of symabolic constants by the OP.
The OP didn't deserve that and everyone who responded just made fun of
him/her. You took part in a session where people kept making worse
versions of the original preprocessor defines. Not everyone has been
roaming c.l.c and programming in C for ages, so lighten up "a little"
or apply the same strict rules you enforce on yourself.


Yes, quite frankly, the OP did deserve to be mocked. He's been told
many times before, over several years, that his macros serve only to
make his code more difficult to read. He doesn't seem to care whether
he's actually communicating, which makes many of us wonder why he
wastes his time (and ours) by posting here. Perhaps I should have
just ignored it, but in this case I chose not to.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 23 '05 #11
TTroy wrote:
.... snip ...
In the thread titled: "Do you like my strlcpy strlcat etc?" you
join in with other posters to mock the use of symabolic constants
by the OP. The OP didn't deserve that and everyone who responded
just made fun of him/her. You took part in a session where people
kept making worse versions of the original preprocessor defines.
Not everyone has been roaming c.l.c and programming in C for ages,
so lighten up "a little" or apply the same strict rules you
enforce on yourself.


Yes he did deserve it. This is far from the first time he has been
told about it. The best use for trolls is as butts for jokes.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Jul 23 '05 #12
On Sat, 05 Feb 2005 23:35:27 GMT, CBFalconer <cb********@yah oo.com>
wrote:
TTroy wrote:

... snip ...

In the thread titled: "Do you like my strlcpy strlcat etc?" you
join in with other posters to mock the use of symabolic constants
by the OP. The OP didn't deserve that and everyone who responded
just made fun of him/her. You took part in a session where people
kept making worse versions of the original preprocessor defines.
Not everyone has been roaming c.l.c and programming in C for ages,
so lighten up "a little" or apply the same strict rules you
enforce on yourself.


Yes he did deserve it. This is far from the first time he has been
told about it. The best use for trolls is as butts for jokes.


I had thought on str[l]cpy str[l]cat
there is no need of strcpy, strcat they are easily emulate
with some loop (so strcpy strcat are errors)
For me your str[l]cpy has at last one error
if p is a pointer to char and sizeof(array pointed from p)=sz
if the array of chars poited from p have no 0 in the first sz-1
positions => str[l]cpy has to end it with a 0 in the sz-1 position.

I think strlcpy strlcat are too errors
I think there is only the need
sprintf for fast and accurate programming (that can emulate strcpy and
strcat)
and something like
snprintf(char* buffer, size_t size, char* fmt, ...); (that can emulate
strlcpy strlcat)
for everyday functions

the same for malloc:
one malloc for fast and accurate programming and a malloc2 that can
find the errors in memory for write out of bouds etc for everyday
functions

Then if you like a buggy language ...

Jul 23 '05 #13
On Sat, 05 Feb 2005 22:28:10 GMT, Keith Thompson <ks***@mib.or g>
wrote:
"TTroy" <ti*****@gmail. com> writes:
[...]
I don't think Mike meant the OP was truly lying for the purpose of
confusing c.l.c readers. He probably meant it as if he was suprised,
kind of like if someone says something unbelievable you might respond:
"No way, you're lying."

He did further go on to help the OP, so lighten up Keith. If you're
going to be such a hard a*s about every post on c.l.c. that is even a
little OT, incorrect or improper, then lead by example.
Read Mike's reaponse (which you probably hadn't seen when you posted
yours).
In the thread titled: "Do you like my strlcpy strlcat etc?" you join in
with other posters to mock the use of symabolic constants by the OP.
The OP didn't deserve that and everyone who responded just made fun of
him/her. You took part in a session where people kept making worse
versions of the original preprocessor defines. Not everyone has been
roaming c.l.c and programming in C for ages, so lighten up "a little"
or apply the same strict rules you enforce on yourself.


Yes, quite frankly, the OP did deserve to be mocked. He's been told
many times before, over several years, that his macros serve only to
make his code more difficult to read. He doesn't seem to care whether
he's actually communicating, which makes many of us wonder why he
wastes his time (and ours) by posting here.


If you lost your time reading my message kill file my messages
but I think these macro are Right and ok because read these macro is
more easy for me.
Perhaps I should have
just ignored it, but in this case I chose not to.


Jul 23 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
630
by: Hans | last post by:
Hello, Why all C/C++ guys write: const char* str = "Hello"; or const char str = "Hello";
15
416
by: Hans | last post by:
Hello, Thanks for all your response on my question about signed/unsigned chars. The problem is this: I want to use the char array for a ArrayLookup, so I need to convert char to unsigned int. But this doesn't work! If I try this:
3
2354
by: lovecreatesbeauty | last post by:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the "hello, world" thing using the name "string-constant". But `ISO/IEC 9899:TC2' does not include this kind of thing in section `A.1.5 Constants'.
10
5359
by: fei.liu | last post by:
Consider the following sample code char * ptr = "hello"; char carray = "hello"; int main(void){ } What does the standard have to say about the storage requirement about ptr and carray? Is it a fair statement that char *ptr will take 4 more bytes (on 32bit platform) in DATA segment? I have found
3
2817
by: amanjsingh | last post by:
I want to know what is the origin of Hello World program and who wrote it, what language it was written in and why was Hello World chosen as a phrase? Thanks a lot AJ
1
10085
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.