473,441 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

how do I tell whether the read is an English letter or a number

QQ
for instance, I read a char from the input
and I need to decide whether it is a letter or a number
What I am doing is
char a;
...... // read a
int true = false;
if( (a >='0') && (a <='z')
true = 1;
Is there any easy way for it?
Thanks a lot!

Jun 7 '06 #1
13 1884
"QQ" <ju****@yahoo.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
for instance, I read a char from the input
and I need to decide whether it is a letter or a number
What I am doing is
char a;
..... // read a
int true = false;
if( (a >='0') && (a <='z')
true = 1;
Is there any easy way for it?
untested junk follows:

#include <ctype.h>
#include <stdio.h>
#include <string.h>
....
char string[32767];
if (fgets(string, sizeof string, stdin))
{
int i;
int ival;
for (i = 0; i < strlen(string); i++)
ival = string[i];
if (isalpha(ival)) puts("letter");
if (isdigit(ival)) puts("digit");
if (ispunct(ival)) puts("punctuation");
}
}
Thanks a lot!

Jun 7 '06 #2

QQ wrote:
for instance, I read a char from the input
and I need to decide whether it is a letter or a number
What I am doing is
char a;
..... // read a
int true = false;
if( (a >='0') && (a <='z')
true = 1;
This is not portable since it depends on the way your platform codes
characters
and digits. It won't work with ASCII encoding.
Is there any easy way for it?


Yes and it's called isalnum()

Spiros Bousbouras

Jun 7 '06 #3
QQ wrote:
for instance, I read a char from the input
and I need to decide whether it is a letter or a number
Have a look at the is.... macros form the standard library, isalnum(),
probably does what you want.
What I am doing is
char a;
...... // read a
int true = false;


Not a good choice of variable name.

--
Ian Collins.
Jun 7 '06 #4
Dann Corbit wrote:
How to decide whether it is an English letter or a number? char a;
..... // read a
int true = false;
if(( (a >='0') && (a <='9')) | | ((a >='a') && (a <= 'z')) ||((a >='A')
&& (a <= 'Z')))
true = 1;


Once again this depends on the character encoding. There's no
guarantee that everything >= 'a' and <= 'z' will be a letter.

I also notice that you ask for *English* letter. I don't know
if the value of the locale affects the behaviour of isalnum()
but I suspect that it does. You would need to use setlocale()
to select the appropriate locale for the English language.

Jun 7 '06 #5
sp****@gmail.com wrote:

Dann Corbit wrote:
How to decide whether it is an English letter or a number?

char a;
..... // read a
int true = false;
if(( (a >='0') && (a <='9')) | | ((a >='a') && (a <= 'z')) ||((a >='A')
&& (a <= 'Z')))
true = 1;


Once again this depends on the character encoding.


What are you quoting?
I can't find that text and I can't find that code
anywhere else in this thread,

--
pete
Jun 7 '06 #6

pete wrote:
sp****@gmail.com wrote:

Dann Corbit wrote:
How to decide whether it is an English letter or a number?

char a;
..... // read a
int true = false;
if(( (a >='0') && (a <='9')) | | ((a >='a') && (a <= 'z')) ||((a >='A')
&& (a <= 'Z')))
true = 1;


Once again this depends on the character encoding.


What are you quoting?
I can't find that text and I can't find that code
anywhere else in this thread,


I am quoting the first message of the thread titled "How to decide
whether it
is an English letter or a number?". I figured since both threads
discuss the same
topic it would be best to have all the comments together in one.

Jun 7 '06 #7
sp****@gmail.com wrote:

pete wrote:
sp****@gmail.com wrote:

Dann Corbit wrote:

> How to decide whether it is an English letter or a number?
What are you quoting?
I am quoting the first message of the thread titled
"How to decide whether it
is an English letter or a number?".
No, you aren't quoting anything that anybody ever wrote.

This is from that thread:

"for instance, I read a char from the input
and I need to decide whether it is a letter or a number"
I figured since both threads
discuss the same
topic it would be best to have all the comments together in one.


Then you should quote the thread that you are replying to,
and let the other thread die.

--
pete
Jun 7 '06 #8

pete wrote:
sp****@gmail.com wrote:

pete wrote:
sp****@gmail.com wrote:
>
> Dann Corbit wrote:
>
> > How to decide whether it is an English letter or a number? What are you quoting?
I am quoting the first message of the thread titled
"How to decide whether it
is an English letter or a number?".


No, you aren't quoting anything that anybody ever wrote.

This is from that thread:

"for instance, I read a char from the input
and I need to decide whether it is a letter or a number"


And below that is the code I quoted. I also quoted the title of the
thread.
I figured since both threads
discuss the same
topic it would be best to have all the comments together in one.


Then you should quote the thread that you are replying to,
and let the other thread die.


I did quote the thread I was replying to. Or do you mean I should
(only) quote the thread *in which* I'm replying to ? Why should I
restrict
myself like this ? Although I guess I should have mentioned that I
was quoting another thread to avoid confusion.

I felt that the opening post of the other thread would benefit from a
comment so I wasn't willing to just let it die.

Jun 7 '06 #9
sp****@gmail.com wrote:

pete wrote:
sp****@gmail.com wrote:

pete wrote:

> sp****@gmail.com wrote:
> >
> > Dann Corbit wrote:
> >
> > > How to decide whether it is an English letter or a number?
Or do you mean I should
(only) quote the thread *in which* I'm replying to ? Why should I
restrict myself like this ?


I'll post the answer to that question, in another thread.

BTW, you didn't quote any of what Dann Corbit actually posted.

--
pete
Jun 7 '06 #10

pete wrote:
BTW, you didn't quote any of what Dann Corbit actually posted.


You are right , I was quoting QQ and for some reason I thought that
Dann Corbit had written the message.

Jun 8 '06 #11
sp****@gmail.com wrote:
Dann Corbit wrote:
How to decide whether it is an English letter or a number?

char a;
..... // read a
int true = false;
if(( (a >='0') && (a <='9')) | | ((a >='a') && (a <= 'z')) ||((a >='A')
&& (a <= 'Z')))
true = 1;


Once again this depends on the character encoding. There's no
guarantee that everything >= 'a' and <= 'z' will be a letter.


Dan Corbit wrote nothing of the sort and knows much better than to
write such junk. Try to take some elementary care with your
quotations.

--
"Our enemies are innovative and resourceful, and so are we.
They never stop thinking about new ways to harm our country
and our people, and neither do we." -- G. W. Bush.
"The people can always be brought to the bidding of the
leaders. All you have to do is tell them they are being
attacked and denounce the pacifists for lack of patriotism
and exposing the country to danger. It works the same way
in any country." --Hermann Goering.

Jun 8 '06 #12
sp****@gmail.com wrote:

pete wrote:
BTW, you didn't quote any of what Dann Corbit actually posted.


You are right , I was quoting QQ and for some reason I thought that
Dann Corbit had written the message.


Why aren't you using the real quote mechanism from Google instead of
cutting and pasting?

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Jun 8 '06 #13

Default User wrote:
sp****@gmail.com wrote:

pete wrote:
BTW, you didn't quote any of what Dann Corbit actually posted.


You are right , I was quoting QQ and for some reason I thought that
Dann Corbit had written the message.


Why aren't you using the real quote mechanism from Google instead of
cutting and pasting?


Because I was quoting from a different thread.

Jun 11 '06 #14

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

Similar topics

3
by: smjmitchell | last post by:
Hi, I am writing an application in VB6.0 that will have the option to select the language. For instance when Spanish is selected all the text on the program interface will display in Spanish. ...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
9
by: Papiya | last post by:
The proble is how can i include any picture, let it be any bitmap file to my c program..... i want to display a bitmap file using C/C++ Hope somebody will help me Please reply if u know solution...
14
by: Gidi | last post by:
Hi, For the last week, i'm looking for a way to make a TextBox always write in English (No matter what the OS default language is). i asked here few times but the answers i got didn't help me. i...
10
by: QQ | last post by:
for instance, I read a char from the input and I need to decide whether it is a letter or a number What I am doing is char a; ...... // read a int true = false; if(( (a >='0') && (a <='9')) | |...
3
by: socondc22 | last post by:
Im stuck at this point. The way i was trying to do this was running if statement around my void function and then a else if statement around a different void function but it didnt work... right now...
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
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
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
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,...
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...
0
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...

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.