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?
Printable View
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.
#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;
}
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).
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.
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.
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.
yeah i need from 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D etc across and again down. then everything lines up so it looks like a table.
peckitt99: You've been given enough help to make your initial attempt. Start posting your own code or you will be perceived as a leech. And demonstrate your interest in a helpful answer by posting your attempt in code tags.
ok sorry, im just new to all of this.
Why not use type casting within a loop, quite simple really.
You don't need a typecast.
Quzah.
i have finally got the table using gotoxy but i am now having troubles getting the ascii inside the table. because at the moment i have to row and coloum and then the ascii is underneith. this is the code i have so far
Code:#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main ()
{
unsigned int ch; //ch is the unsigned integer
int line;
gotoxy (3,1);
cprintf("00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
gotoxy(1,3);
for (line=0x0; line <0x0F; line++)
cprintf("%x\r\n",line);
for ( ch = 0x00; ch < 0xFF; ch++ )// to output all the charactures.
{
cprintf(" %c ", ch);//print all the characters from ch
if ( !(ch % 16 ) )
putchar('\n');
}
printf ("\n\n\n");
system("pause");
}
What is gotoxy() for? Other than making your code non-portable, of course. Just print the header on the first line, then print the characters on subsequent lines, making sure they line up. Drop <conio.h>, it's non-standard. And system("pause") is not too good either.