Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Question in C (http://www.velocityreviews.com/forums/t741058-question-in-c.html)

Mateusz_madi 12-29-2010 05:42 PM

Question in C
 
Hi why when i write:
printf("%c", \11); i get S??

Mark Storkamp 12-29-2010 06:09 PM

Re: Question in C
 
In article
<50abe663-51cf-43d3-8537-6ea38d203f05@i17g2000vbq.googlegroups.com>,
Mateusz_madi <madi.czadi@gmail.com> wrote:

> Hi why when i write:
> printf("%c", \11); i get S??


That's odd, I get "error: stray '\' in program"

How about posting a copy of a complete compilable program.

Coos Haak 12-29-2010 06:15 PM

Re: Question in C
 
Op Wed, 29 Dec 2010 09:42:11 -0800 (PST) schreef Mateusz_madi:

> Hi why when i write:
> printf("%c", \11); i get S??


You don't, the program will not compile because of a stray '\'.

--
Coos

Kenny McCormack 12-29-2010 06:19 PM

Re: Question in C
 
In article <1r8b8h7qw4v7e.zdqydjbbhi4e$.dlg@40tude.net>,
Coos Haak <chforth@hccnet.nl> wrote:
>Op Wed, 29 Dec 2010 09:42:11 -0800 (PST) schreef Mateusz_madi:
>
>> Hi why when i write:
>> printf("%c", \11); i get S??

>
>You don't, the program will not compile because of a stray '\'.


Interesting that you say that...

On my system, I get S, just like the OP.

--
One of the best lines I've heard lately:

Obama could cure cancer tomorrow, and the Republicans would be
complaining that he had ruined the pharmaceutical business.

(Heard on Stephanie Miller = but the sad thing is that there is an awful lot
of direct truth in it. We've constructed an economy in which eliminating
cancer would be a horrible disaster. There are many other such examples.)

Mateusz_madi 12-29-2010 06:19 PM

Re: Question in C
 
That's the whole code:

----------------------
#include<stdio.h>

char input[]="SSSWILTECH1\1\11W\1WALLMP1";

main()
{
int i,c;


for( i=2; (c=input[i])!='\0'; i++){
switch(c){
case 'a' : putchar('i'); continue;
case '1' : break;
case 1 : while( (c=input[++i])!='\1' && c!='\0');
case 9 : putchar('S');
case 'E' : case 'L' : continue;
default : putchar(c); continue;
}
putchar(' ');
}
putchar('\n');
}
------------------------
Additionally i have question how: /*case 'E' : case 'L' : continue; */
works, and what is the difference between /* case 1 */ and /* case '1'
*/

Regards

Ralf Damaschke 12-29-2010 06:42 PM

Re: Question in C
 
gazelle@shell.xmission.com (Kenny McCormack) wrote:

> [...] Coos Haak <chforth@hccnet.nl> wrote:
>>Op Wed, 29 Dec 2010 09:42:11 -0800 (PST) schreef Mateusz_madi:
>>
>>> Hi why when i write:
>>> printf("%c", \11); i get S??

>>
>>You don't, the program will not compile because of a stray '\'.

>
> Interesting that you say that...
>
> On my system, I get S, just like the OP.


OK, then I suggest you to study your compiler documentation for
the meaning of the diagnostic message "S". You apparently know
little about C, but believe me: the statement above requires a
diagnostic message and those have to be documented by the
implementation.

-- Ralf

Kenny McCormack 12-29-2010 06:53 PM

Re: Question in C
 
In article <Xns9E5DC86CC4642dammel@y2plugh.fqdn.th-h.de>,
Ralf Damaschke <rwspam@gmx.de> wrote:
>gazelle@shell.xmission.com (Kenny McCormack) wrote:
>
>> [...] Coos Haak <chforth@hccnet.nl> wrote:
>>>Op Wed, 29 Dec 2010 09:42:11 -0800 (PST) schreef Mateusz_madi:
>>>
>>>> Hi why when i write:
>>>> printf("%c", \11); i get S??
>>>
>>>You don't, the program will not compile because of a stray '\'.

>>
>> Interesting that you say that...
>>
>> On my system, I get S, just like the OP.

>
>OK, then I suggest you to study your compiler documentation for
>the meaning of the diagnostic message "S". You apparently know
>little about C, but believe me: the statement above requires a
>diagnostic message and those have to be documented by the
>implementation.
>
>-- Ralf


Gotcha!

--
One of the best lines I've heard lately:

Obama could cure cancer tomorrow, and the Republicans would be
complaining that he had ruined the pharmaceutical business.

(Heard on Stephanie Miller = but the sad thing is that there is an awful lot
of direct truth in it. We've constructed an economy in which eliminating
cancer would be a horrible disaster. There are many other such examples.)

Mateusz_madi 12-29-2010 07:00 PM

Re: Question in C
 
Ok, wrong question asked, why: printf("%d", '\11'); gives 9 ?? What
this \ means ?

Ben Pfaff 12-29-2010 07:01 PM

Re: Question in C
 
Mateusz_madi <madi.czadi@gmail.com> writes:

> Ok, wrong question asked, why: printf("%d", '\11'); gives 9 ?? What
> this \ means ?


In this case, it introduces an octal constant. Octal 11 is
decimal 9.
--
Ben Pfaff
http://benpfaff.org

Mateusz_madi 12-29-2010 07:04 PM

Re: Question in C
 
HA! That mae sense, so when i put in the test "something...\12" values
\xx will mean the same as 012??
Regards



All times are GMT. The time now is 09:58 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.