473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sign ' is the same as \' ?

Hello everyone,
I am surprised to see that the value of sign ' is the same as \'. So,
there is no need to add sign \ before sign '? In my past knowledge of
sign ', we always need to add sign \ before sign '. Any comments?

Here is my simple program to test.

Expand|Select|Wrap|Line Numbers
  1. #include <string.h>
  2.  
  3. int main (int argc, char** argv)
  4. {
  5. char* p1 = "Hello \'World\'";
  6. char* p2 = "Hello 'World'";
  7. int result = 0;
  8.  
  9. result = strcmp(p1, p2);
  10.  
  11. return 0;
  12. }
  13.  

thanks in advance,
George
Nov 23 '07 #1
10 1755
In article <e8**********************************@a39g2000pre. googlegroups.com>,
George2 <ge*************@yahoo.comwrote:
>I am surprised to see that the value of sign ' is the same as \'. So,
there is no need to add sign \ before sign '?
There's no need to put a backslash before a single quote in a string,
but in a character constant you need it:

char *s = "'";
char c = '\'';

Conversely you need a backslash before a double quote in a string, but
not in a character constant:

char *s = "\"";
char c = '"';

You are allowed to use the backslashed forms even when not necessary.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 23 '07 #2
George2 wrote:
Hello everyone,
I am surprised to see that the value of sign ' is the same as \'. So,
there is no need to add sign \ before sign '? In my past knowledge of
sign ', we always need to add sign \ before sign '. Any comments?
This snippet

char ch = 'a';
printf ("It's Jon%cs\n", ch);

.... prints "It's Jonas". Your mission, should you choose to
accept it, is to change the first line to make the output be
"It's Jon's".

--
Eric Sosman
es*****@ieee-dot-org.invalid
Nov 23 '07 #3
Eric Sosman wrote:
George2 wrote:
>Hello everyone,
I am surprised to see that the value of sign ' is the same as \'. So,
there is no need to add sign \ before sign '? In my past knowledge of
sign ', we always need to add sign \ before sign '. Any comments?

This snippet

char ch = 'a';
printf ("It's Jon%cs\n", ch);

... prints "It's Jonas". Your mission, should you choose to
accept it, is to change the first line to make the output be
"It's Jon's".
How do you propose to make your posting self-destruct?
Nov 23 '07 #4
Mark Bluemel wrote:
Eric Sosman wrote:
>George2 wrote:
>>Hello everyone,
I am surprised to see that the value of sign ' is the same as \'. So,
there is no need to add sign \ before sign '? In my past knowledge of
sign ', we always need to add sign \ before sign '. Any comments?

This snippet

char ch = 'a';
printf ("It's Jon%cs\n", ch);

... prints "It's Jonas". Your mission, should you choose to
accept it, is to change the first line to make the output be
"It's Jon's".

How do you propose to make your posting self-destruct?
Unnecessary; I'll just deny all knowledge.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Nov 23 '07 #5

"George2" <ge*************@yahoo.comwrote in message
news:e8**********************************@a39g2000 pre.googlegroups.com...
Hello everyone,
I am surprised to see that the value of sign ' is the same as \'. So,
there is no need to add sign \ before sign '? In my past knowledge of
sign ', we always need to add sign \ before sign '. Any comments?

Here is my simple program to test.

Expand|Select|Wrap|Line Numbers
  1. #include <string.h>
  2. int main (int argc, char** argv)
  3. {
  4. char* p1 = "Hello \'World\'";
  5. char* p2 = "Hello 'World'";
  6. int result = 0;
  7. result = strcmp(p1, p2);
  8. return 0;
  9. }
  10.  
Context, context, context.

char c = '\''; /* apostrophe in character literal */
char *s = "'"; /* apostrophe in string literal */

char c = '"'; /* quote in character literal */
char *s = "\""; /* quote in string literal */

char c = '''; /* invalid */
char *s = """; /* invalid */

-Mike
Nov 23 '07 #6
Eric Sosman wrote:
George2 wrote:
>Hello everyone,
I am surprised to see that the value of sign ' is the same as \'. So,
there is no need to add sign \ before sign '? In my past knowledge of
sign ', we always need to add sign \ before sign '. Any comments?

This snippet

char ch = 'a';
printf ("It's Jon%cs\n", ch);

... prints "It's Jonas". Your mission, should you choose to
accept it, is to change the first line to make the output be
"It's Jon's".
char ch = '\'';

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 23 '07 #7
"Mike Wahler" <mk******@mkwahler.neta écrit dans le message de news:
13*************@corp.supernews.com...
>
"George2" <ge*************@yahoo.comwrote in message
news:e8**********************************@a39g2000 pre.googlegroups.com...
>Hello everyone,
I am surprised to see that the value of sign ' is the same as \'. So,
there is no need to add sign \ before sign '? In my past knowledge of
sign ', we always need to add sign \ before sign '. Any comments?

Here is my simple program to test.

Expand|Select|Wrap|Line Numbers
  1. #include <string.h>
  2. int main (int argc, char** argv)
  3. {
  4. char* p1 = "Hello \'World\'";
  5. char* p2 = "Hello 'World'";
  6. int result = 0;
  7. result = strcmp(p1, p2);
  8. return 0;
  9. }

Context, context, context.

char c = '\''; /* apostrophe in character literal */
char *s = "'"; /* apostrophe in string literal */

char c = '"'; /* quote in character literal */
char *s = "\""; /* quote in string literal */

char c = '''; /* invalid */
char *s = """; /* invalid */
Since you cannot have an empty character constant, ''' is not ambiguous, so
it could be allowed.

For the OP: now that you understand quoting issues better, how does C handle
triple quoting à la python:

char *s3 = """'""";

And what is wrong with these:

char c2 = '""';
char c3 = '"""';

--
Chqrlie.
Nov 26 '07 #8
Charlie Gordon wrote:
....
And what is wrong with these:

char c2 = '""';
char c3 = '"""';
Nothing, as far as I can see, though the value stored in c2 and c3 is
implementation-defined.
Nov 26 '07 #9
Charlie Gordon wrote:
[...]
Since you cannot have an empty character constant, ''' is not ambiguous, so
it could be allowed.
int ch = ''' + ''';

What value do you suggest ch should have? Twice the
value of '\'', or the implementation-defined value of a
character literal containing seven characters, or something
else?

--
Eric Sosman
es*****@ieee-dot-org.invalid
Nov 26 '07 #10
"Eric Sosman" <es*****@ieee-dot-org.invalida écrit dans le message de
news: Ac******************************@comcast.com...
Charlie Gordon wrote:
>[...]
Since you cannot have an empty character constant, ''' is not ambiguous,
so it could be allowed.

int ch = ''' + ''';

What value do you suggest ch should have? Twice the
value of '\'', or the implementation-defined value of a
character literal containing seven characters, or something
else?
Good point. Thus exits ''' for '\'';

But then why disallow the empty character constant ?
We could make the empty character constant have the value 0. That would
improve readability of code dealing with ends of strings:

if (str[i] == '') {
return i;
}

It would be somewhat consistent with the string literal syntax:

char *s = "";
assert(*s == '');

I'll wait till April 1st, 2008 to submit this one for consideration in C20XY

--
Chqrlie.
Nov 26 '07 #11

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

Similar topics

9
by: cooldv | last post by:
i know how to replace the sign " when SUBMITTING a form in asp by this code: message = Replace(usermessage, "'", "''"). My problem is DISPLAYING data in an asp FORM, from an an access database,...
12
by: tarmat | last post by:
sorry for this silly little question, but whats the function to grab the sign of a value?
37
by: Claude Gagnon | last post by:
Hi, How can we compare sign of numbers in C++ ? Bye, Claude
10
by: Sona | last post by:
Hi, Could someone please explain what sign-extension means? If I have a hex number 0x55, how does this get sign-extended? Can a sign-extended counterpart be equal to -91? In a program I'm...
3
by: Jimmy | last post by:
I'm trying to find a website that does the following: 1. Signs you up to a second site under a different primary domain (i.e. as a result of a checkout or something). The username and password may...
6
by: Steve K. | last post by:
I recall a few months ago coming across an article allowing for encoding (or converting?) xml and html documents into sign language as well as brail for deaf and blind people, and that they were...
11
by: =?ISO-8859-1?Q?Konrad_M=FChler?= | last post by:
Hi, a simple question: Which standard function in c++ gives me the sign of a number? Thanks Konrad
2
by: Terry Chapman | last post by:
I have a 2003 Access .mda add-in which I can sign using my Thawte digital certificate. I am now migrating this add-in to Access 2007 and when I try to add my Thawte digital signature Access 2007...
29
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my...
20
by: Ravikiran | last post by:
Hi Friends, I wanted know about whatt is ment by zero optimization and sign optimization and its differences.... Thank you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.