Question in C

N

Nick

Seebs said:
Since I am a total fucking moron whose head is so far up his ass
that I wear Klein bottle sweaters

Is that an original - because I'm not going to forget it and want to
give it the corrent credit if I ever come to use it.
 
L

luser- -droog

That's the whole code:

Okay, the question you wrote then is probably the worst-asked question
I've ever seen on Usenet.  What you wrote is totally, completely,
and utterly unlike the actual code in every way.
char input[]="SSSWILTECH1\1\11W\1WALLMP1";

Okay, so, you have a \11 here.
      case 9 : putchar('S');

Look, you have something that does a putchar('S')!

But the \11 should be skipped by the action of the \1 case.
One 'S' appears to come from starting on i=2.

By my read-thru, the output should be:
S W I T C H W A M P
 
S

Seebs

Is that an original - because I'm not going to forget it and want to
give it the corrent credit if I ever come to use it.

I don't know. I made that comment or a close relative without being aware
of prior art back in the late 80s or early 90s, but it's quite possible that
there have been others, or even that I'd seen them and then forgotten about
them.

It really does seem tailor-made for "Kenny", though.

-s
 
R

Ralf Damaschke


Yes, if you feel proud that I answered to a regular group troll.
However I felt if you spread misinformation like that, that have
to be corrected. Feel free to spread your usual personal insults,
I won't care.

-- Ralf
 
S

Seebs

Yes, if you feel proud that I answered to a regular group troll.
However I felt if you spread misinformation like that, that have
to be corrected. Feel free to spread your usual personal insults,
I won't care.

There are two possibilities. One is that he successfully trolled you.
The other is that he was lying to stir up trouble, and then pretended
to have been fooling to try to save face.

Considering his obsession with status and appearances, the latter seems
much more likely. He's not the sort to get something right when he
can just lie about it later.

-s
 
E

Edward A. Falk

But the \11 should be skipped by the action of the \1 case.
One 'S' appears to come from starting on i=2.

I believe that the \<digit> form introduces an octal code, e.g. \o,
\oo, \ooo, depending on how many digits the parser finds after the \
character. In your case, it saw two digits, which is '\11' which would
be equivalent to the the ocatal value 011, which is the decimal value 9,
which is why your "case 9:" got executed.
 
G

Geoff

That's the whole code:

Okay, the question you wrote then is probably the worst-asked question
I've ever seen on Usenet.  What you wrote is totally, completely,
and utterly unlike the actual code in every way.
char input[]="SSSWILTECH1\1\11W\1WALLMP1";

Okay, so, you have a \11 here.
      case 9 : putchar('S');

Look, you have something that does a putchar('S')!

But the \11 should be skipped by the action of the \1 case.
One 'S' appears to come from starting on i=2.

By my read-thru, the output should be:
S W I T C H W A M P


In this case actually compiling and running it reveals the program's
correct output and true nature.

SWITCH SWAMP

Appropriate, is it not?

Another example of why debuggers/emulators can be superior to
human-playing-computer-in-his-head games.

The original program, corrected and commented.

#include<stdio.h>

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

int main(void)
{
int i,c;


for( i=2; (c=input)!='\0'; i++) //from 3rd char to null char
{
switch(c){ //based on input character
case 'a' : putchar('i'); continue;
case '1' : break; // never print a 1 char
case 1 : while( (c=input[++i])!='\1' && c!='\0');
case 9 : putchar('S'); // find the hidden ascii
case 'E' : case 'L' : continue; //back to top
default : putchar(c); continue; //catch fall-throughs
}
putchar(' '); //when all cases fail, print a space
}
putchar('\n'); //all done
return 0;
}
 
S

Seebs

case 1 : while( (c=input[++i])!='\1' && c!='\0');
case 9 : putchar('S'); // find the hidden ascii

The gimmick here:

\1\11blahblah\1

skips the whole block, then *falls through* to case 9. The \11 is a
red herring.

-s
 
G

Geoff

case 1 : while( (c=input[++i])!='\1' && c!='\0');
case 9 : putchar('S'); // find the hidden ascii

The gimmick here:

\1\11blahblah\1

skips the whole block, then *falls through* to case 9. The \11 is a
red herring.

-s
And a nice one it is, too.

FWIW, the OP's version of the program is taken verbatim from "The C
Puzzle Book" by Alan R. Feuer, Copyright 1982 by Bell Laboratories, on
page 33, which explains why main() was defined per old C.
 
L

luser- -droog

    case 1 : while( (c=input[++i])!='\1' && c!='\0');
    case 9 : putchar('S');             // find the hidden ascii

The gimmick here:

        \1\11blahblah\1

skips the whole block, then *falls through* to case 9.  The \11 is a
red herring.

Rats! I saw the loop, but not the fall-through.
 
N

Nick Keighley

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

have you consideredreading a book about C? These are very basic
questions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,083
Messages
2,570,589
Members
47,211
Latest member
JaydenBail

Latest Threads

Top