473,785 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

printing all escape sequence characters

consider the following program

/*************** *************** *************** *******/
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
int c;

for (c = '\a'; c <= '\z'; c++)
printf("%c %d\n", c, (int)c);

exit(EXIT_SUCCE SS);
}

/*************** *************** *************** *********/

here I am trying to print all escape sequences (well, most of them are
illegal).

the output is
----------------------------------------
7
8
9

10

11

12
13
14
15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
32
! 33
" 34
# 35
$ 36
% 37
& 38
' 39
( 40
) 41
* 42
+ 43
, 44
- 45
.. 46
/ 47
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
: 58
; 59
< 60
= 61
62
? 63
@ 64
A 65
B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90
[ 91
\ 92
] 93
^ 94
_ 95
` 96
a 97
b 98
c 99
d 100
e 101
f 102
g 103
h 104
i 105
j 106
k 107
l 108
m 109
n 110
o 111
p 112
q 113
r 114
s 115
t 116
u 117
v 118
w 119
x 120
y 121
z 122
--------------------------------------------------

after executing the program I can hear my CPU speaker give away "beep"
sound. This indicates (i presume) that '\a' is outputted correctly. But
what about the other characters that are outputted.

I am using gcc 4.1 on linux.

Oct 28 '06 #1
5 2542
On Sat, 2006-10-28 at 05:25 -0700, chandanlinster wrote:
consider the following program

/*************** *************** *************** *******/
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
int c;

for (c = '\a'; c <= '\z'; c++)
printf("%c %d\n", c, (int)c);

exit(EXIT_SUCCE SS);
}

/*************** *************** *************** *********/
Oh my. This is the most interestingly incorrect algorithm I have seen
in a long while. Congratulations . :-)

Your fatal flaw is that the sequences '\a' to '\z' are /not/ guaranteed
to be in contiguous order, and they almost certainly will not be in real
life. (I'm not even sure of the consequences of using invalid escape
sequences like '\q'.)

A better algorithm would be:
1. Take a good C book.
2. Locate the page with the table of escape sequences.
3. Scan it.
4. Switch to Algorithm O (optical character recognition)

--
Andrew Poelstra <http://www.wpsoftware. net/projects/>

Oct 28 '06 #2

chandanlinster wrote:
after executing the program I can hear my CPU speaker give away "beep"
sound. This indicates (i presume) that '\a' is outputted correctly. But
what about the other characters that are outputted.

I am using gcc 4.1 on linux.
There are several books and websites that explain what each escape
characters does.

Oct 28 '06 #3
On 28 Oct 2006 05:25:27 -0700, "chandanlinster "
<ch************ @gmail.comwrote :
>consider the following program

/*************** *************** *************** *******/
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
int c;

for (c = '\a'; c <= '\z'; c++)
Didn't your compiler complain that '\z' is an invalid escape sequence
(syntax error)?

By the way, '\n' in ASCII is 0x0a while '\t' is 0x09 so it is obvious
they need not run in order.

You might have more luck using 0 and CHAR_MAX as your limits.
> printf("%c %d\n", c, (int)c);
c is already an int. What do you think the cast accomplishes? Even
if c were a char, for unspecified arguments to a variadic function
char (and short) is always promoted to int. (And float is promoted to
double.)
>
exit(EXIT_SUCCE SS);
}

/*************** *************** *************** *********/

here I am trying to print all escape sequences (well, most of them are
illegal).
Consider yourself lucky that one of them doesn't mean format your hard
drive.
>
the output is
----------------------------------------
7
8
9

10

11

12
13
14
15
 16
snip
> 31
32
! 33
" 34
# 35
$ 36
% 37
& 38
' 39
( 40
) 41
* 42
+ 43
, 44
- 45
. 46
/ 47
0 48
snip
>9 57
: 58
; 59
< 60
= 61
>62
? 63
@ 64
A 65
snip
>Z 90
[ 91
\ 92
] 93
^ 94
_ 95
` 96
a 97
snip
>z 122
--------------------------------------------------

after executing the program I can hear my CPU speaker give away "beep"
sound. This indicates (i presume) that '\a' is outputted correctly. But
what about the other characters that are outputted.
Well, the value 9 appeared to tab over consistent with its definition
as horizontal tab. The value 8 should have backspaced but I'll bet
your system swallowed it because it knew you were at the beginning of
a line. The value 10 did produce a new line consistent with its
definition as line feed. So did values 11 and 12 which I guess is one
of the valid interpretations of vertical tab and form feed as it
applies to displays. Values 16-31 are apparently unprintable which is
consistent with their definitions.

What did you expect? What is your real question?
>
I am using gcc 4.1 on linux.

Remove del for email
Oct 28 '06 #4

"Barry Schwarz" <sc******@doezl .netha scritto nel messaggio
news:1d******** *************** *********@4ax.c om...
On 28 Oct 2006 05:25:27 -0700, "chandanlinster "
<ch************ @gmail.comwrote :
consider the following program

/*************** *************** *************** *******/
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
int c;

for (c = '\a'; c <= '\z'; c++)

Didn't your compiler complain that '\z' is an invalid escape sequence
(syntax error)?

By the way, '\n' in ASCII is 0x0a while '\t' is 0x09 so it is obvious
they need not run in order.

You might have more luck using 0 and CHAR_MAX as your limits.
printf("%c %d\n", c, (int)c);

c is already an int. What do you think the cast accomplishes? Even
if c were a char, for unspecified arguments to a variadic function
char (and short) is always promoted to int. (And float is promoted to
double.)
Not always.

If char is "unsigned" and int cannot represent all values of "unsigned char"
char is promoted to unsigned int, signed char is always
promoted to int.

--
Giorgio Silvestri
DSP/Embedded/Real Time OS Software Engineer

Oct 28 '06 #5
Barry Schwarz wrote:
>
On 28 Oct 2006 05:25:27 -0700, "chandanlinster "
<ch************ @gmail.comwrote :
consider the following program
[...]
for (c = '\a'; c <= '\z'; c++)
[...]
printf("%c %d\n", c, (int)c);
[...]
What did you expect? What is your real question?
[...]

I think he expected c to loop as:

'\a'
'\b'
'\c'
'\d'
...
'\x'
'\y'
'\z'

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>

Oct 31 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3456
by: Joe | last post by:
I'm using Python 2.4 on Windows XP SP2. I'm trying to receive a command line argument that is a newline (\n) Here is the command line to use sample.py "\n" Here is a sample.py script
5
4087
by: Kit | last post by:
Hey there, and thanks for reading a newbie post. I have a lex assignment in which we are supposed to grab strings from a C source file, and print them out to the screen, with escaped characters "converted". Here's part of the assignment text: ---------------------------------------------------------------- Example: main() { char *s = "This is string one";
6
6657
by: Walter L. Preuninger II | last post by:
I need to convert escape sequences entered into my program to the actual code. For example, \r becomes 0x0d I have looked over the FAQ, and searched the web, with no results. Is there a function that can do this, or do I need to use predefined constants or a table of the values? Below is a sample program. When run with the input w\rx, I want to see the output::
7
96330
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %% should be used. Wouldn't it have been better (from design perspective) if the same escape character had been used in this case too. Forgive me for posting without verfying things with any standard compiler, i don't have the means for now.
4
7472
by: Guadala Harry | last post by:
I need to place the following into a string... How can I properly escape the % " / < and > characters? <table width="100%" border="0" cellspacing="0" cellpadding="4px" class="hfAll"></Table> Thanks.
12
9645
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" & Chr(34) & PopUpWindowTitle & Chr(34) & ", " & Chr(34) & CurrentEventDetails & ")" strTemp += "<BR><A HREF='#' onClick='" & PopupLink & "'>" & EventName & "</A><BR>" The problem I have is that when the string variables or contain a string with an...
7
4188
by: Axel Dahmen | last post by:
Hi, within a DataGrid control I'm using a DataTable containing a string column to fill a Hyperlink's href attribute. Unfortunately HttpUtility.UrlEncode() doesn't escape the apostroph character, thus ruining some of my hrefs. How do I correctly escape any character using a Page's current encoding (I don't want to hard-code the encoding)? TIA,
15
18321
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN. Any idea if this is a bug? if (e.KeyChar == '\e') { this.Close(); }
9
3426
by: Rui Maciel | last post by:
Is there a function which takes a string and outputs another equivalent string where all the non-ASCII characters (i.e., escapable characters) are replaced with the respective escape character sequence (i.e., '\t', '\n', "\uXXXX"). Thanks in advance Rui Maciel
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.