hi could someone help me .
Exist some function in c or c++ or visul c++ to do a conversion from ASCII character in decimal number???
please help me
thanks in advance

Recommended Answers

All 3 Replies

There is no function because there is no need for one. What you see is how you choose to interpret it.

#include <stdio.h>

int main(void)
{
   char ch = '*';
   printf("ch = '%c'\n", ch);
   printf("ch = %d\n", ch);
   return 0;
}

/* my output
ch = '*'
ch = 42
*/

the problem is that i have a text file like 100kb full of ascii character and i want anything to translate them in decimal.do you have other ideas.

Doing so would be a big loop with code similar to the above, unless I am misunderstanding. I am assuming that you are saying something like this:

Input:

The quick brown fox jumps over the lazy dog.

Output:

84 104 101 32 113 117 105 99 107 32 98 114 111 119 110 32 102 111 120 32 106 117 109 112 115 32 111 118 101 114 32 116 104 101 32 108 97 122 121 32 100 111 103 46

This is the code that generated the above.

#include <stdio.h>

int main(void)
{
   static const char ch[] = "The quick brown fox jumps over the lazy dog.";
   int i;
   for ( i = 0; ch[i]; ++i )
   {
      printf("%d ", ch[i]);
   }
   putchar('\n');
   return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.