Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing ASCII 1

Status
Not open for further replies.

GirishGupta

Programmer
May 28, 2001
30
GB
This isn't really a question specific to Borland C++ but it is C.

Does anyone know how to print ASCII code in C.

Code:
printf("\\97");

That doesn't work... Girish Gupta
girish@musicgoeson.com
 
i tried it on my compiler, it works fine for me. What doesn't work about it? You could try something like:
printf((char*)"\\97");
Cyprus
 
The following code:

Code:
#include <stdio.h>

void main()
{
 printf(&quot;\\97\n&quot;);
 printf((char*)&quot;\\97\n&quot;);
 char i = getchar();
}

...outputs:

Code:
\97
\97

Any ideas why it doesn't work for me? Girish Gupta
girish@musicgoeson.com
 
Greetinx!

Its correct output so after this code has been executed really output will be '\97'.

For more infos see BorlandC++Builder Help on topic 'Escape sequences'. Happy programming!))
 
I still don't understand how to it, or what I'm doing wrong... Girish Gupta
girish@musicgoeson.com
 
you could just go the easy route and do

char c = 97;
printf(&quot;%c = %d&quot;,c,(int)c);

Matt
 
Brilliant!!! Thanks!

I've created the following:

Code:
#include <stdio.h>

void main()
{
 int i = 0;
 while (i<=256)
 {
  printf(&quot;%c = %d \n\n&quot;,i,(int)i);
  i++;
 }
 char g = getchar();
}
Girish Gupta
girish@musicgoeson.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top