i am trying to write a program that will output an ascii table. the only way i can think of doing this is to write them all out line by line, but i have heard that you can do this in a loop. i am unsure how to do this in a loop.
can anyone help?
i am trying to write a program that will output an ascii table. the only way i can think of doing this is to write them all out line by line, but i have heard that you can do this in a loop. i am unsure how to do this in a loop.
can anyone help?
There are 255 of them plus NULL. So from 0 to 256. You can printf like printf("%c %d 0x%x\n", i, i, i); in aloop afcourse.
Last edited by andor; 10-06-2006 at 08:08 AM.
#include<stdio.h>
int main()
{
char ch=0;
int i;
for(i=0;i<=122;i++)
{
printf("%c \n",ch);
ch++;
}
getchar();
return 0;
}
Bear in mind that several of the ASCII characters are non-printable and will have "unexpected" effects if you attempt to print them. You might want to look at isprint() in ctype.h
Better than what most people could hardcode:
http://www.lookuptables.com/
the code above is what i need but i put it in (prob not what i was ment to but i have not used C before) and it didnt do anything. is there anything im doing wrong?
It really doesn't get any easier than:
While Skeane is correct in his post, very little of the ASCII table is printable, but they do hold some value. If you want to see how your terminal renders that value, some risk is involved.Code:#include <stdio.h> int main ( void ) { unsigned int ch; for ( ch = 0; ch < 0xFF; ch++ ) { printf("%3d 0x%X %c ", ch, ch, ch); if ( !(ch % 4 ) ) putchar('\n'); } return 0; }
Last edited by whiteflags; 10-07-2006 at 01:38 PM.
cool, thanx
Like screwing up display completely because you just accidently replaced the console character set. Happens easily on Linux if you 'cat' a binary file.
Someone kind-of mentioned it, but here's it explicitely: ASCII has only 127 characters, from 0x00 to 0x7F. All higher values are extensions, like Windows-1252 (Win9x standard), ISO-8859-1 (Linux standard) or IBM/OEM-850 (DOS and Windows console standard on German systems).
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
just one more question, how do u create a table to put them in?
"Now, just a simple question, how do I make the graphics for my game?"
This isn't a simple question. You'd need to make a GUI application for that.
"The Internet treats censorship as damage and routes around it." - John Gilmore
ok not a table like that just headings so you can see what each characture represents if you know what i i mean eg...
0 1 2 4
0
1
2
3
etc...
Why do you need a lookup table at all? I fail to see the point of lookup tables for characters in this case.
Quzah.
Hope is the first step on the road to disappointment.
im not sure its just what the tutor wants and it is for uni so best do it. i know i need to use gotoxy i think unless there is an easier way. i just dont know how to implement it into ma code.
So you're just trying to print a grid? Print across until you're bored, then print a newline. Repeat until done.
Quzah.
Hope is the first step on the road to disappointment.