[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 886
  • 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 AkbarnejadCommented:
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!

 
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
 
trinitrotolueneCommented:
"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

Featured Post

Industry Leaders: 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!

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