Solved

Which letter or digit ??

Posted on 2000-03-25
2
286 Views
Last Modified: 2010-04-02
How can i determine the  letter or digit from its ASCII code easily/efficiently. I  currently use the switch statement and i have 26 cases for letter and 10 for digit.
i.e.
 switch (letr)
      {
     case 97:
     {
      strcpy(ltr,"a");
      ltr[1] = '\0';
      strcat(expression_buffer,ltr);
      ltr[0] = '\0';
     };break;//end
     .
     .
     .
     case 122:
     {
      strcpy(ltr,"z");
      ltr[1] = '\0';
      strcat(expression_buffer,ltr);
      ltr[0] = '\0';
     };break;//end


and the same thing for digits!!!!

This  makes my code too big

Pls help me find a better way of doing this.

I'm using turbo C++

All suggestions are welcome.

Thanks in advance.
0
Comment
Question by:onalenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 50 total points
ID: 2657433
You could just place the ASCII character in your character array. For example:

if (isalpha(letr) || isdigit(letr))
  {
  ltr[0] = letr;
  ltr[1] = '\0';
  }
0
 
LVL 22

Expert Comment

by:nietod
ID: 2657583
Also (and this is a step in the wrong direction, because Steve's suggestion is clearly better, but for future reference) you can always use a single character in place a number representing the character's aSCII value, for example you could have done

 switch (letr)
{
case 'a':
{
strcpy(ltr,"a");
ltr[1] = '\0';
strcat(expression_buffer,ltr);
ltr[0] = '\0';
};break;//end
case 'b':

etc.

That should be much clearer to understand.  Obviously, don't do it now!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question