473,738 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ascii numbers

Dan
Some knows how to verify an ascii code.
I want to verify a char for the list of ascii codes between 64 to 122.
Mainly in other words, check a char, look if its in a range of ascii code
and output a bool, true or false.
thanks

D
Jul 22 '05 #1
19 2279
Dan wrote:
Some knows how to verify an ascii code.
I want to verify a char for the list of ascii codes between 64 to 122.
Mainly in other words, check a char, look if its in a range of ascii
code and output a bool, true or false.
thanks

D


template<class T>
bool isbetween(T c, T l, T u)
{
if(l > u) std::swap(l, u);
return c >= l && c <= u;
}

int main()
{
bool c_between_64_12 2 = isbetween('c', 64, 122);
}

As a bonus, it works for any type where operators >, >=, and <= are defined.

- Pete
Jul 22 '05 #2
Dan
template<class T>
bool isbetween(T c, T l, T u)
{
if(l > u) std::swap(l, u);
return c >= l && c <= u;
}

int main()
{
bool c_between_64_12 2 = isbetween('c', 64, 122);
}

As a bonus, it works for any type where operators >, >=, and <= are defined.
- Pete

Thats pretty cool stuff.
I can see that return c >= l && c <= u will return a bool value for values
between 64 and 122 only if the conditions above are met. What I want to know
is your 'c' , I guess this is you input ? do you declare it as a char
array? so as to make it

int main()
{
char c;

cout<<"Press a key " ;
cin>> c;

bool c_between_64_12 2 = isbetween('c', 64, 122);
if (bool == true) { cout<< "It is in there" <<endl; }
if (bool == false) {cout<< "It is not in there" <<endl; }


Jul 22 '05 #3
Dan wrote:
template<class T>
bool isbetween(T c, T l, T u)
{
if(l > u) std::swap(l, u);
return c >= l && c <= u;
}
<snip>
Thats pretty cool stuff.
I can see that return c >= l && c <= u will return a bool value for
values between 64 and 122 only if the conditions above are met. What
I want to know is your 'c' , I guess this is you input ? do you
declare it as a char array? so as to make it

int main()
{
char c;

cout<<"Press a key " ;
cin>> c;

bool c_between_64_12 2 = isbetween('c', 64, 122);
if (bool == true) { cout<< "It is in there" <<endl; }
if (bool == false) {cout<< "It is not in there" <<endl; }


'c' is a character constant I randomly picked to demo it, to make your
example work correctly:

#include <iostream>
using std::cout;
using std::endl;

#include <algorithm>

template<class T>
bool isbetween(T c, T l, T u)
{
if(l > u) std::swap(l, u);
return c >= l && c <= u;
}

int main()
{
char c;
cout << "Enter a character: " ;
cin >> c;
cout << endl;

bool c_between_64_12 2 = isbetween(c, 64, 122);
if (c_between_64_1 22)
cout << "It is in there" << endl;
else
cout << "It is not in there" << endl;

return 0;
}

- Pete
Jul 22 '05 #4
> template<class T>
bool isbetween(T c, T l, T u)
{
if(l > u) std::swap(l, u);
return c >= l && c <= u;
}
bool c_between_64_12 2 = isbetween('c', 64, 122);


Now, I didn't get this... Where do you define T for the clas template?
Or do all have to be of the same type? I would have expected something
like:
isbetween<char> ('c', 64, 122)
No?
You're puzzling me here... And I thought I understood templates...
-Gernot
Jul 22 '05 #5
Gernot Frisch wrote in news:2j******** ****@uni-berlin.de in
comp.lang.c++:
template<class T>
bool isbetween(T c, T l, T u)
{
if(l > u) std::swap(l, u);
return c >= l && c <= u;
}
bool c_between_64_12 2 = isbetween('c', 64, 122);
Now, I didn't get this... Where do you define T for the clas template?


T is deduced.
Or do all have to be of the same type?
Yes they do.
I would have expected something
like:
isbetween<char> ('c', 64, 122)
No? You're puzzling me here... And I thought I understood templates...


The bit you have missed is that 'c' is passed as an int, so template
argument deduction succeds with T = int. The call is effectivly:

isbetween( int >( 'c', 64, 122 );

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #6
Rob Williscroft wrote in news:Xns950864E DDF118ukcoREMOV Efreenetrtw@
130.133.1.4 in comp.lang.c++:
isbetween( int >( 'c', 64, 122 );


isbetween< int >( 'c', 64, 122 );

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #7

"Gernot Frisch" <Me@Privacy.net > wrote in message
news:2j******** ****@uni-berlin.de...
template<class T>
bool isbetween(T c, T l, T u)
{
if(l > u) std::swap(l, u);
return c >= l && c <= u;
}
bool c_between_64_12 2 = isbetween('c', 64, 122);


Now, I didn't get this... Where do you define T for the clas template?
Or do all have to be of the same type? I would have expected something
like:
isbetween<char> ('c', 64, 122)
No?
You're puzzling me here... And I thought I understood templates...
-Gernot


Yes that should be

bool c_between_64_12 2 = isbetween('c', (char)64, (char)122);

or as you had it

bool c_between_64_12 2 = isbetween<char> ('c', 64, 122);

or alternatively

template<class T, class U>
bool isbetween(T c, U l, U u)
{
if(l > u) std::swap(l, u);
return c >= l && c <= u;
}

john
Jul 22 '05 #8
I stand corrected.

john
Jul 22 '05 #9
Dan

"Gernot Frisch" <Me@Privacy.net > wrote in message
news:2j******** ****@uni-berlin.de...
template<class T>
bool isbetween(T c, T l, T u)
{
if(l > u) std::swap(l, u);
return c >= l && c <= u;
}
bool c_between_64_12 2 = isbetween('c', 64, 122);


Now, I didn't get this... Where do you define T for the clas template?
Or do all have to be of the same type? I would have expected something
like:
isbetween<char> ('c', 64, 122)
No?
You're puzzling me here... And I thought I understood templates...
-Gernot


after compiling
error C2782: 'bool __cdecl isbetween(T,T,T )' : template parameter 'T' is
ambiguous
D
Jul 22 '05 #10

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

Similar topics

17
1754
by: Doug Fort | last post by:
This is an excerpt from a much longer post on the python-dev mailing list. I'm responding here, to avoid cluttering up python-dev. <snip> >Some English readers might not really imagine, but it is a constant >misery, having to mangle identifiers while documenting and thinking >in languages other than English, merely because the Python notion of >letter is limited to the English subset. Granted, keywords and standard >library use...
37
10166
by: chandy | last post by:
Hi, I have an Html document that declares that it uses the utf-8 character set. As this document is editable via a web interface I need to make sure than high-ascii characters that may be accidentally entered are properly represented when the document is served. My programming language allows me to get the ascii value for any individual character so what I am doing when a change is saved is to look at each character in the content and...
6
2035
by: Willem | last post by:
What is the best way to calculate an ascii string into an integer (not talking about an atoi conversion): For examle if I have the ascii string: "/b" then in hex it would be 2F7A and if I convert that to decimal I would get 12154. I can't figure out how to concatenate? my hex values together if that makes any sense? Any pointers would be greatly appreciated!
12
1984
by: IamIan | last post by:
I searched the archives but couldn't find anyone else with this problem. Basically I'm grabbing all ASCII files in a directory and doing geoprocessing on them. I need to calculate a z-factor based on the latitude of the ASCII file being worked on, which is in the filename. If I type in the code manually it works and reads the latitude value from the ASCII filename, but when run within ArcGIS it crashes when it gets to int(LatString)....
3
2415
by: Willing 2 Learn | last post by:
Hey, I'm trying to teach myself C++ and I came across 3 problems. I understand the concept of FSA but getting the C++ code to do it as become an issue. Only thing is im clueless as to how to do them; these are: 1) Devise a coding system to send CAPITAL LETTERS using the ASCII code. Assume the lights will be ON when you start sending, and use OFF for ZERO and ON for ONE. 2. I want to use this code to send letters to someone else by...
19
32832
by: many_years_after | last post by:
Hi,everyone: Have you any ideas? Say whatever you know about this. thanks.
399
12877
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or to python-3000@python.org In summary, this PEP proposes to allow non-ASCII letters as identifiers in Python. If the PEP is accepted, the following identifiers would also become valid as class, function, or variable names: Löffelstiel,...
14
7983
by: Peter Sprenger | last post by:
Hello, I want to efficient convert floating point numbers (IEEE754) into a string. I have no library routines that do the job (like sprintf etc.), because I work in an embedded environment. My actual algorithm uses multiplying with 10 to shift the fraction into an integer value and to aquire the used exponent. But the drawback is obvious: When I have very small numbers like 3.141E-300 I have to make 300 time consuming floating point...
4
25068
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. Anybody please help in c language. Thanks in Advance.
0
9334
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
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
8208
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...
0
6053
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
4569
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
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
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
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.