Solved

# Converting alphabet to ascii

Posted on 2010-09-18
815 Views
How to convert an alphabet to ascii equivalent in C?
0
Question by:manishk1111

LVL 40

Expert Comment

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

ID: 33710346
char a = 'a';
0

LVL 14

Accepted Solution

ID: 33710352
int asciiCode;
char c = 'A';
asciiCode = (int) c;
printf("%d", asciiCode);

or

printf("%d",c);

-FA
0

LVL 3

Expert Comment

ID: 33710364
The ASCII table is:

http://www.asciitable.com/

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

LVL 9

Expert Comment

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;

}
``````
0

LVL 84

Expert Comment

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

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

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

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

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

LVL 84

Expert Comment

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.