0

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

2
Contributors
3
Replies
4
Views
12 Years
Discussion Span
Last Post by Dave Sinkula
0

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
*/
0

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.

0

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;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.