Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

hi friends

9 views
Skip to first unread message

appi

unread,
Jun 27, 2006, 6:05:20 AM6/27/06
to
I am learning datastructure using c in my syllabus and i want to learn
about datastructure, c++, java, oracle, web design, html,c#.


SO I AM REQUESTING YOU THAT PLEASE SEND ME SOME INFORMATION
ABOUT THE ABOVE MENTIONED TOPICS.

AND ALSO SEND ME SOME INFORMATION ABOUT INTERNET.

YOURS FAITHFULLY
KIRAN.M.K

Chris Dollin

unread,
Jun 27, 2006, 6:02:42 AM6/27/06
to
appi wrote:

> AND ALSO SEND ME SOME INFORMATION ABOUT INTERNET.

Shouting on Usenet does not get you friends.

--
Chris "hush" Dollin
"People are part of the design. It's dangerous to forget that." /Star Cops/

Vladimir Oka

unread,
Jun 27, 2006, 6:08:22 AM6/27/06
to

Internet lesson 1: SHOUTING AT PEOPLE IS VERY VERY RUDE!

Usenet lesson 1: comp.lang.c deals with C not any of the other stuff
you mention.

c.l.c lesson 1:
<http://www.clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Good luck!

Richard Heathfield

unread,
Jun 27, 2006, 6:18:48 AM6/27/06
to
appi said:

#include <stdio.h>
#include <ctype.h>

int main(void)
{
int ch;
while((ch = getchar()) != EOF)
{
putchar(tolower((unsigned char)ch));
}

return 0;
}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Skarmander

unread,
Jun 27, 2006, 7:44:12 AM6/27/06
to
Richard Heathfield wrote:
> appi said:
>
>> I am learning datastructure using c in my syllabus and i want to learn
>> about datastructure, c++, java, oracle, web design, html,c#.
>>
>>
>> SO I AM REQUESTING YOU THAT PLEASE SEND ME SOME INFORMATION
>> ABOUT THE ABOVE MENTIONED TOPICS.
>>
>> AND ALSO SEND ME SOME INFORMATION ABOUT INTERNET.
>>
>> YOURS FAITHFULLY
>> KIRAN.M.K
>
> #include <stdio.h>
> #include <ctype.h>
>
> int main(void)
> {
> int ch;
> while((ch = getchar()) != EOF)
> {
> putchar(tolower((unsigned char)ch));
<snip>

What is the cast supposed to accomplish here? If I've understood the
standard correctly, nothing.

Is it supposed to accomplish something in general? If 'ch' were not
representable as an unsigned char, you avoid undefined behavior with an
explicit conversion, but since the end result is still indeterminate to a
portable program, this doesn't seem like a big win (it's a small win, since
you at least know your program will output gibberish at the worst, rather
than launch the nuclear missiles, but still).

If invalid values are expected, the program should handle their occurrence
explicitly. If the most appropriate explicit handling turns out to be
converting the values explicitly and hoping for the best, then that's fine,
but I wouldn't insert that reflexively.

S.

pete

unread,
Jun 27, 2006, 8:13:41 AM6/27/06
to
Skarmander wrote:
>
> Richard Heathfield wrote:

> > putchar(tolower((unsigned char)ch));

> What is the cast supposed to accomplish here? If I've understood the
> standard correctly, nothing.
>
> Is it supposed to accomplish something in general?

Yes.
If ch is a negative value,
and if ((unsigned char)ch) compares equal to 'A',
then putchar(ch) will output 'A'.

--
pete

Skarmander

unread,
Jun 27, 2006, 8:20:20 AM6/27/06
to
But why would this be useful? How would you obtain such values, and why
would you use them?

S.

pete

unread,
Jun 27, 2006, 8:41:55 AM6/27/06
to

In the C locale,
which is what the program in question was,
I don't think it matters.

But I took your phrase "in general"
to imply "regardless of locale".

N869
7.4 Character handling <ctype.h>

[#2] The behavior of these functions is affected by the
current locale.

--
pete

Skarmander

unread,
Jun 27, 2006, 9:11:35 AM6/27/06
to
"Regardless of locale" just means the program can't assume a particular
locale to be in effect.

I didn't mean to ask if there was some possibility that the statement
putchar(tolower((unsigned char) ch));
occurring in some program, using some locale, has a reason for the cast to
be there. Of course there will be such programs and locales. The question is
whether there's any other interpretation of that cast *in general* than a
slightly questionable attempt at error handling.

Either the value you're working with is expected, or it isn't. If it isn't,
converting makes little sense (except to convert potentially undefined
behavior into potentially gibberish output, which may have some extrinsic
value). If it is, converting makes sense only for some particular algorithm
in combination with some particular locales, which was not the context I was
talking about.

S.

santosh

unread,
Jun 27, 2006, 9:29:50 AM6/27/06
to
appi wrote:
> I am learning datastructure using c in my syllabus and i want to learn
> about datastructure, c++, java, oracle, web design, html,c#.

Are all of the above included in your syllabus!?

Try to learn one langauge at a time. It's better to know one or two
langauges really well than hack around with several langauges. I
suggest you learn C, SQL and HTML to start with. I personally favour
Python instead of Java or C++, but YMMV.

> SO I AM REQUESTING YOU THAT PLEASE SEND ME SOME INFORMATION
> ABOUT THE ABOVE MENTIONED TOPICS.

Firstly, using all caps is considered as shouting. We've left Yahoo!
Chat; we're in Usenet.
Also this group deals with standard C and not general programming. You
might want to post to comp.programming, *but*, before you do that, be
sure to read the information at the following URLs.

<http://cfaj.freeshell.org/google/>
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
<http://www.safalra.com/special/googlegroupsreply/>
<http://en.wikipedia.org/wiki/USENET>
<http://en.wikipedia.org/wiki/Netiquette>

> AND ALSO SEND ME SOME INFORMATION ABOUT INTERNET.

I assume you know how to use Google... ?

santosh

unread,
Jun 27, 2006, 9:35:50 AM6/27/06
to
Richard Heathfield wrote:
> appi said:
>
> > I am learning datastructure using c in my syllabus and i want to learn
> > about datastructure, c++, java, oracle, web design, html,c#.
> >
> >
> > SO I AM REQUESTING YOU THAT PLEASE SEND ME SOME INFORMATION
> > ABOUT THE ABOVE MENTIONED TOPICS.
> #include <stdio.h>
> #include <ctype.h>
>
> int main(void)
> {
> int ch;
> while((ch = getchar()) != EOF)
> {
> putchar(tolower((unsigned char)ch));

Is the cast here necessary?

> }
>
> return 0;
> }

Richard Heathfield

unread,
Jun 27, 2006, 11:22:28 AM6/27/06
to
Skarmander said:

> Richard Heathfield wrote:
>> appi said:
>>
>>> I am learning datastructure using c in my syllabus and i want to learn
>>> about datastructure, c++, java, oracle, web design, html,c#.
>>>
>>>
>>> SO I AM REQUESTING YOU THAT PLEASE SEND ME SOME INFORMATION
>>> ABOUT THE ABOVE MENTIONED TOPICS.
>>>
>>> AND ALSO SEND ME SOME INFORMATION ABOUT INTERNET.
>>>
>>> YOURS FAITHFULLY
>>> KIRAN.M.K
>>
>> #include <stdio.h>
>> #include <ctype.h>
>>
>> int main(void)
>> {
>> int ch;
>> while((ch = getchar()) != EOF)
>> {
>> putchar(tolower((unsigned char)ch));
> <snip>
>
> What is the cast supposed to accomplish here? If I've understood the
> standard correctly, nothing.

Since getchar returns an unsigned char converted to int, you're right in
this case. I was over-egging.

> Is it supposed to accomplish something in general?

Yes. Consider the following code:

#include <stdio.h>
#define MAXLINE 1024
int main(void)
{
char line[MAXLINE];
while(fgets(line, sizeof line, stdin) != NULL)
{
size_t i;
for i = 0; line[i] != '\0'; i++)
{
putchar(tolower(line[i])); /* BUG - see below */
}
}
return 0;
}

Consider a user who manages to input "special characters" (e.g. in MS-DOS,
he types Alt-0156 to get a UKP sign), that are not in the range 0 to
UCHAR_MAX. fgets will capture these correctly, as unsigned chars, but then
assign them into members of the line array, which are chars. If we continue
with our MS-DOS example, the char value will be *negative*. When this value
is passed to tolower(), it will be promoted to int, but it will still be
negative. So if tolower() is implemented as an array lookup (which is
perfectly legal), the offset into that array will be negative for this
character. Bang, as they say. Converting the character to unsigned char
explicitly, on the other hand, means that everything comes out in the wash
and the character is handled correctly.

Richard Heathfield

unread,
Jun 27, 2006, 11:36:53 AM6/27/06
to
santosh said:

> Richard Heathfield wrote:
<snip>


>>
>> int main(void)
>> {
>> int ch;
>> while((ch = getchar()) != EOF)
>> {
>> putchar(tolower((unsigned char)ch));
>
> Is the cast here necessary?

It's one of those times when a habit that /can/ save your bacon /doesn't/
save your bacon because, in this exact circumstance, your bacon is not
endangered. That doesn't mean it's a mistake to have developed the habit.

Skarmander

unread,
Jun 27, 2006, 11:46:19 AM6/27/06
to
Richard Heathfield wrote:
> Skarmander said:
>
>> Richard Heathfield wrote:
<snip>

Thanks, this is what I was looking for. The problem is not that "invalid"
characters are read, but that 'char' may be signed, whereas the various
character functions expect an unsigned char converted to int.

That's a neat gotcha.

S.

Keith Thompson

unread,
Jun 27, 2006, 5:43:23 PM6/27/06
to

<HTTP://WWW.CATB.ORG/~ESR/FAQS/SMART-QUESTIONS.HTML>

Oops, sorry, I meant

<http://www.catb.org/~esr/faqs/smart-questions.html>

--
Keith Thompson (The_Other_Keith) 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.

Chris Hills

unread,
Jun 28, 2006, 4:29:52 AM6/28/06
to
In article <ln64img...@nuthaus.mib.org>, Keith Thompson <kst-
u...@mib.org> writes

>"appi" <coolki...@gmail.com> writes:
>> I am learning datastructure using c in my syllabus and i want to learn
>> about datastructure, c++, java, oracle, web design, html,c#.
>>
>>
>> SO I AM REQUESTING YOU THAT PLEASE SEND ME SOME INFORMATION
>> ABOUT THE ABOVE MENTIONED TOPICS.
>>
>> AND ALSO SEND ME SOME INFORMATION ABOUT INTERNET.
>>
>> YOURS FAITHFULLY
>> KIRAN.M.K
>
><HTTP://WWW.CATB.ORG/~ESR/FAQS/SMART-QUESTIONS.HTML>
>
>Oops, sorry, I meant
>
><http://www.catb.org/~esr/faqs/smart-questions.html>
>

I heard you the first time :-)

We could of course actually do what he asks for the next 30 days, send
*ALL* the information you have on datastructures, C++ etc etc to his
email address....

How many Gb does a Gmail account hold?
Be careful what you wish for :-)

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch...@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Joe Van Dyk

unread,
Jun 29, 2006, 4:11:26 PM6/29/06
to
Richard Heathfield wrote:
> santosh said:
>
>
>>Richard Heathfield wrote:
>
> <snip>
>
>>>int main(void)
>>>{
>>> int ch;
>>> while((ch = getchar()) != EOF)
>>> {
>>> putchar(tolower((unsigned char)ch));
>>
>>Is the cast here necessary?
>
>
> It's one of those times when a habit that /can/ save your bacon /doesn't/
> save your bacon because, in this exact circumstance, your bacon is not
> endangered. That doesn't mean it's a mistake to have developed the habit.

Mmmm... bacon.

Joe

0 new messages