How do you print the ASCII control characters?
How do you print the ASCII control characters?
To print any ASCII characters, I think, it's the same thing.
By the way I dont know what's a control character.Code:printf("%c",ASCII_character);
HOPE YOU UNDERSTAND.......
By associating with wise people you will become wise yourself
It's fine to celebrate success but it is more important to heed the lessons of failure
We've got to put a lot of money into changing behavior
PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
Here is the code that prints all the ASCII characters
Code:#include<stdio.h> int main(void) { int i; for(i=0;i<=255;i++) printf("\n%c",i); }
HOPE YOU UNDERSTAND.......
By associating with wise people you will become wise yourself
It's fine to celebrate success but it is more important to heed the lessons of failure
We've got to put a lot of money into changing behavior
PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
what is the a control character?
Control characters are characters that represent some formatting action, rather than a printable letter. So instead of 'a', 'A', etc... Formatting characters are numbers that are interpreted as "new-line", "carriage-return", "backspace", etc... I guess tabs could also be considered control characters in a sense.
ASCII provides a rather limited set of control characters. Libraries like ncurses provide access to more sequences that are recognized by terminals and terminal emulators, allowing you to even construct windowed apps from the command-line.
If fgetc comes across one of these control characters, is it possible to print them? with printf?
It probably depends on your shell / terminal emulator. I know it was back in the days of real DOS, because I did an exercise with that in Turbo C. However some of that functionality might have been disabled in newer versions of Windows. So to answer your question, I know it did in DOS, but now I'm not so sure. Remember also that not all the control characters are for visual formatting. ^C for instance signals the end of the text, but that doesn't necessarily have any meaning for the screen, and so you'll actually see "^C" get printed to the screen should you press that combination.
edit: http://www.csgnetwork.com/asciiset.html is a quick reference if you need one
Why doesn't this print ^I where i have a tab?
Code:if(iscntrl(c)){ c+64; printf("^%c", c); }
That's not how it works.
Contra BEN10, there are 128 ASCII characters, not 255. "ctrl" is not one of them.
Table of ASCII Characters
If you want "see" what the actual character is, you can get this number:
print("%d", c);
for values 0-127, or
print("%x", c);
for hex values 00-7f
The hex values are handy if you want to dump a bunch of text, because they are all two digits:
Code:void hextext (char *text) { int i, len = strlen(text); for (i=0; i<len; i++) { printf("%x ", text[i]); if (!(i%25)) printf("\n"); } }
Last edited by MK27; 08-10-2009 at 11:13 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
Hmmm i think i need some clarification of the unix cat command.
Using the unix command: cat -v file.txt gives no evidence of any control characters. Shouldn't there be newline control characters at the end of each line?
file.txt:
here is a line.
more line.
after some blanks.
the end.
The cat manual page states that "-v" shows all control characters EXCEPT newline and tab
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
BEN10 & coolskyboy: take a look at this ASCII chart of all characters:
Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion
The first 32 are usually referred to as 'control characters'. They may cause unpredictable activities when thrown out to a display or printer. Such as advance the paper, pause data flow, start a new line, etc. Rather than the rest which are 'printable' - that is, those that make ink flow and advance the cursor nicely.
It sure is strange that people don't know these things instinctively. We all should have lived through the mechanical Teletype days. That would straighten everyone out!
Why is this code resulting in 2 I's being printed?
here is line1.
^IIafter a tab.
^II^IItwo tabs!
the end.
Code:if(iscntrl(c) && tflag && c != '\n'){ c += 64; printf("^%c", c); }
Let me guess: after this, you have something like
which will print that I again (instead of putting it in an else, so that only one or the other print would happen).Code:if (isalpha(c)) { printf("%c", c); }