C
Chris Dollin
appi said:AND ALSO SEND ME SOME INFORMATION ABOUT INTERNET.
Shouting on Usenet does not get you friends.
appi said:AND ALSO SEND ME SOME INFORMATION ABOUT INTERNET.
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
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
<snip>Richard said:appi said:
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int ch;
while((ch = getchar()) != EOF)
{
putchar(tolower((unsigned char)ch));
Skarmander said:Richard Heathfield wrote:
What is the cast supposed to accomplish here? If I've understood the
standard correctly, nothing.
Is it supposed to accomplish something in general?
But why would this be useful? How would you obtain such values, and whypete said:Yes.
If ch is a negative value,
and if ((unsigned char)ch) compares equal to 'A',
then putchar(ch) will output 'A'.
Skarmander said:But why would this be useful?
How would you obtain such values, and why
would you use them?
"Regardless of locale" just means the program can't assume a particularpete said:Skarmander said:But why would this be useful?
How would you obtain such values, and why
would you use them?
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.
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.
I assume you know how to use Google... ?AND ALSO SEND ME SOME INFORMATION ABOUT INTERNET.
Richard said:appi said:
#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?
Richard Heathfield wrote:
Is the cast here necessary?
Richard said:Skarmander said:
Richard Heathfield wrote:
<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 != '\0'; i++)
{
putchar(tolower(line)); /* 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*.
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
Keith Thompson <kst- said:
Richard said:santosh said:
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.
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.