Printing "tab"

J

Julian V. Noble

mdh said:
I wrote a little insignificant program, to help me write a more
significant one!!...that was supposed to print all Ascii values from 0
to 127:


#include <stdio.h>
# define UPPER_LIMT 127

int main (){

int i;

printf("%7s%7s\n\n", "Decimal", "Value");
for ( i=0; i<= UPPER_LIMT; i++)
printf( "%3d%7c\n", i, i);
return 0;
}


However, I would like to see, for example, 'TAB' instead of an
upside-down question mark, at decimal value '9'. Is there a
conversion I could use for this in printf?

Thanks in advance.

A 128-entry conversion table would do it. The entries are
strings. At decimal enter "TAB", at 32 enter "BLANK", etc.
Print the strings in the table.
 
P

phil

mdh said:
I wrote a little insignificant program, to help me write a more
significant one!!...that was supposed to print all Ascii values from 0
to 127:


#include <stdio.h>
# define UPPER_LIMT 127

int main (){

int i;

printf("%7s%7s\n\n", "Decimal", "Value");
for ( i=0; i<= UPPER_LIMT; i++)
printf( "%3d%7c\n", i, i);
return 0;
}


However, I would like to see, for example, 'TAB' instead of an
upside-down question mark, at decimal value '9'. Is there a
conversion I could use for this in printf?

Thanks in advance.
 
J

Joe Wright

CBFalconer said:
#include <limits.h>
...
unsigned int ch;
for (ch = 0; ch < UCHAR_MAX; ch++) {
if (isprint(ch) {
/* output the printing char as you please */
}
else {
/* deal with the non-printing char */
}
}

I wrote this several years ago. It may be of interest here. Note that
ASCII 0..31 are controls and not printable. Also 127 is not printable.

#include <stdio.h>
/*
The complete ASCII table is defined so that this program might
run as well on a machine whose native character set is not ASCII.
*/
char *ascii[] = {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS ", "HT ", "LF ", "VT ", "FF ", "CR ", "SO ", "SI ",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM ", "SUB", "ESC", "FS ", "GS ", "RS ", "US ",
" ", " ! ", " \" "," # ", " $ ", " % ", " & ", " ' ",
" ( ", " ) ", " * ", " + ", " , ", " - ", " . ", " / ",
" 0 ", " 1 ", " 2 ", " 3 ", " 4 ", " 5 ", " 6 ", " 7 ",
" 8 ", " 9 ", " : ", " ; ", " < ", " = ", " > ", " ? ",
" @ ", " A ", " B ", " C ", " D ", " E ", " F ", " G ",
" H ", " I ", " J ", " K ", " L ", " M ", " N ", " O ",
" P ", " Q ", " R ", " S ", " T ", " U ", " V ", " W ",
" X ", " Y ", " Z ", " [ ", " \\ "," ] ", " ^ ", " _ ",
" ` ", " a ", " b ", " c ", " d ", " e ", " f ", " g ",
" h ", " i ", " j ", " k ", " l ", " m ", " n ", " o ",
" p ", " q ", " r ", " s ", " t ", " u ", " v ", " w ",
" x ", " y ", " z ", " { ", " | ", " } ", " ~ ", "DEL"
};
int main(void) {
int i;
size_t asiz = sizeof ascii / sizeof *ascii;
for (i = 0; i < asiz; ++i) {
if (i % 8 == 0) printf("\n|");
printf("%3d %s|", i, ascii);
}
return 0;
}
 
J

Jordan Abel

Joe Wright said:
I wrote this several years ago. It may be of interest here. Note that
ASCII 0..31 are controls and not printable. Also 127 is not printable.

#include <stdio.h>
/*
The complete ASCII table is defined so that this program might
run as well on a machine whose native character set is not ASCII.
*/
char *ascii[] = {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS ", "HT ", "LF ", "VT ", "FF ", "CR ", "SO ", "SI ",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM ", "SUB", "ESC", "FS ", "GS ", "RS ", "US ",
" ", " ! ", " \" "," # ",
" \u0024 ",
" % ", " & ", " ' ",
" ( ", " ) ", " * ", " + ", " , ", " - ", " . ", " / ",
" 0 ", " 1 ", " 2 ", " 3 ", " 4 ", " 5 ", " 6 ", " 7 ",
" 8 ", " 9 ", " : ", " ; ", " < ", " = ", " > ", " ? ", " \u0040 ",
" A ", " B ", " C ", " D ", " E ", " F ", " G ",
" H ", " I ", " J ", " K ", " L ", " M ", " N ", " O ",
" P ", " Q ", " R ", " S ", " T ", " U ", " V ", " W ",
" X ", " Y ", " Z ", " [ ", " \\ "," ] ", " ^ ", " _ ", " \u0060 ",
" a ", " b ", " c ", " d ", " e ", " f ", " g ",
" h ", " i ", " j ", " k ", " l ", " m ", " n ", " o ",
" p ", " q ", " r ", " s ", " t ", " u ", " v ", " w ",
" x ", " y ", " z ", " { ", " | ", " } ", " ~ ", "DEL"
};

Three of the characters in your table are not in the basic execution
character set.
 
J

Joe Wright

Jordan said:
Joe Wright said:
I wrote this several years ago. It may be of interest here. Note that
ASCII 0..31 are controls and not printable. Also 127 is not printable.

#include <stdio.h>
/*
The complete ASCII table is defined so that this program might
run as well on a machine whose native character set is not ASCII.
*/
char *ascii[] = {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS ", "HT ", "LF ", "VT ", "FF ", "CR ", "SO ", "SI ",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM ", "SUB", "ESC", "FS ", "GS ", "RS ", "US ",
" ", " ! ", " \" "," # ", " \u0024 ",
" % ", " & ", " ' ",
" ( ", " ) ", " * ", " + ", " , ", " - ", " . ", " / ",
" 0 ", " 1 ", " 2 ", " 3 ", " 4 ", " 5 ", " 6 ", " 7 ",
" 8 ", " 9 ", " : ", " ; ", " < ", " = ", " > ", " ? ", " \u0040 ",
" A ", " B ", " C ", " D ", " E ", " F ", " G ",
" H ", " I ", " J ", " K ", " L ", " M ", " N ", " O ",
" P ", " Q ", " R ", " S ", " T ", " U ", " V ", " W ",
" X ", " Y ", " Z ", " [ ", " \\ "," ] ", " ^ ", " _ ", " \u0060 ",
" a ", " b ", " c ", " d ", " e ", " f ", " g ",
" h ", " i ", " j ", " k ", " l ", " m ", " n ", " o ",
" p ", " q ", " r ", " s ", " t ", " u ", " v ", " w ",
" x ", " y ", " z ", " { ", " | ", " } ", " ~ ", "DEL"
};

Three of the characters in your table are not in the basic execution
character set.

And what exactly does that mean to you? '@' and '`' are printable,
aren't they? That the ASCII 'CAN' control is not in the basic execution
character set is indeed surprising. NOT!

I must have missed something. What is your point?
 
J

Jordan Abel

Joe Wright said:
And what exactly does that mean to you? '@' and '`' are printable,
aren't they? That the ASCII 'CAN' control is not in the basic execution
character set is indeed surprising. NOT!

You didn't include the ascii CAN control in a string literal, only the
letters C, A, and N.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,973
Members
47,529
Latest member
JaclynShum

Latest Threads

Top