• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 929
  • Last Modified:

Converting alphabet to ascii

How to convert an alphabet to ascii equivalent in C?
0
manishk1111
Asked:
manishk1111
1 Solution
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
ozoCommented:
char a = 'a';
0
 
Farzad AkbarnejadDeveloperCommented:
int asciiCode;
char c = 'A';
asciiCode = (int) c;
printf("%d", asciiCode);

or

printf("%d",c);


-FA
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
ashley2009Commented:
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
 
masheikCommented:
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
 
ozoCommented:
   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
 
CEHJCommented:
>>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
 
GanoesCommented:
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
 
trinitrotolueneDirector - Software EngineeringCommented:
"while ( AsciiValue <= 266) {"

ASCII ranges from 0 - 255. The above statement is incorrect.
0
 
ozoCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now