Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Sign ' is the same as \' ?

Reply
Thread Tools

Sign ' is the same as \' ?

 
 
George2
Guest
Posts: n/a
 
      11-23-2007
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.

Code:
#include <string.h>

int main (int argc, char** argv)
{
	char* p1 = "Hello \'World\'";
	char* p2 = "Hello 'World'";
	int result = 0;

	result = strcmp(p1, p2);

	return 0;
}

thanks in advance,
George
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      11-23-2007
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
http://www.velocityreviews.com/forums/(E-Mail Removed)lid
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      11-23-2007
In article <(E-Mail Removed)>,
George2 <(E-Mail Removed)> wrote:

>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.
 
Reply With Quote
 
Mark Bluemel
Guest
Posts: n/a
 
      11-23-2007
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?
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      11-23-2007
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
(E-Mail Removed)lid
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      11-23-2007

"George2" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>
Code:
> #include <string.h>
>
> int main (int argc, char** argv)
> {
> char* p1 = "Hello \'World\'";
> char* p2 = "Hello 'World'";
> int result = 0;
>
> result = strcmp(p1, p2);
>
> return 0;
> }
>
>


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


 
Reply With Quote
 
Joe Wright
Guest
Posts: n/a
 
      11-23-2007
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 ---
 
Reply With Quote
 
Charlie Gordon
Guest
Posts: n/a
 
      11-26-2007
"Mike Wahler" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
>
> "George2" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.
>>
>>
Code:
>> #include <string.h>
>>
>> int main (int argc, char** argv)
>> {
>> char* p1 = "Hello \'World\'";
>> char* p2 = "Hello 'World'";
>> int result = 0;
>>
>> result = strcmp(p1, p2);
>>
>> return 0;
>> }
>>
>>

>
> 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.


 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      11-26-2007
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.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      11-26-2007
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
(E-Mail Removed)lid
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
$ sign to gb pound sign PWB Computer Support 6 02-19-2007 03:06 AM
Automatic sign-up and sign-in across different domains without cookies? Jimmy ASP .Net 1 11-21-2006 04:41 PM
Automatic sign-up and sign-in between different domains without cookies? Jimmy Javascript 3 11-20-2006 01:28 PM
J sign instead of ? sign Harold Potter esq. Computer Support 5 04-16-2005 02:19 PM
Single Sign on for web apps on same box Cowboy \(Gregory A. Beamer\) ASP .Net 1 11-05-2003 07:07 PM



Advertisments