[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Converting alphabet to ascii

Posted on 2010-09-18
12
Medium Priority
?
875 Views
Last Modified: 2012-05-10
How to convert an alphabet to ascii equivalent in C?
0
Comment
Question by:manishk1111
[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
12 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 33710341
Your question, as it stands, doesn't really make a lot of sense. Can you elaborate please so that we may assist you properly?
0
 
LVL 84

Expert Comment

by:ozo
ID: 33710346
char a = 'a';
0
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 2000 total points
ID: 33710352
int asciiCode;
char c = 'A';
asciiCode = (int) c;
printf("%d", asciiCode);

or

printf("%d",c);


-FA
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:ashley2009
ID: 33710364
The ASCII table is:

http://www.asciitable.com/

I think that this article at Bytes might help you. I cannot guarantee as I forgot c and c++:


http://bytes.com/topic/c/answers/769137-how-convert-alphabet-numbers

Another article on c++:
http://www.dreamincode.net/code/snippet566.htm
0
 
LVL 9

Expert Comment

by:masheik
ID: 33710379
Hi,

     A character have its own ASCII-value, you can see it when you represent as integer,
refer ascii table as well,
http://www.asciitable.com/
#include<stdio.h>

int main()
{

  char alpha,c;
  unsigned short asciiValue = 0;
  while(1)
  {
    printf("Enter an alphabet :");
    scanf("%c",alpha);
    asciiValue = (unsigned short) alpha; //Cast required (converts one type to another)
    printf("\n Ascii value of %c is %d \n",alpha, asciiValue);
    /* Revrse what you have done */
    c = (char ) asciiValue; // Cast required
    printf("\n The number %d represents the %c alpha in ascii table \n", asciiValue, c);
    
  }
  return 0;
}

Open in new window

0
 
LVL 84

Expert Comment

by:ozo
ID: 33710435
   scanf("%c",&alpha);
    asciiValue = (unsigned short) alpha; //Cast not required
    printf("\n Ascii value of %c is %d \n",alpha, asciiValue);
    /* Revrse what you have done */
    c = (char ) asciiValue; // Cast not required
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33711377
>>How to convert an alphabet to ascii equivalent in C?

Please don't ask C questions in the Java zone - it just wastes people's time
0
 

Expert Comment

by:Ganoes
ID: 33713867
This gives the decimal equilivant:

#include <iostream>
using namespace std;
int AsciiValue = 0;

int main () {
while ( AsciiValue <= 266) {
cout <<AsciiValue<<" : "<<char(AsciiValue)<<endl;
AsciiValue += 1;
}
cin.get();
}

---

And this will give the hex equilivant:

#include <iostream>
using namespace std;
int AsciiValue = 0;

int main () {
while ( AsciiValue <= 266) {
cout<<"0x";
printf("%X", AsciiValue);
cout <<" : "<<char(AsciiValue)<<endl;
AsciiValue += 1;
}
cin.get();
}
0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 33714399
"while ( AsciiValue <= 266) {"

ASCII ranges from 0 - 255. The above statement is incorrect.
0
 
LVL 84

Expert Comment

by:ozo
ID: 33714657
ASCII ranges from 0 - 127
ISO-8859 ranges from 0 - 255 (which may have been what the asker meant)
and of course all of the answers are wrong if the host environment is EBCDIC
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

656 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