Solved

Which letter or digit ??

Posted on 2000-03-25
2
281 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
2 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 50 total points
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now