0

I'm trying to write a quine program for the follow C source code:

#include<stdio.h>

char name[] = "Jacob Stinson";
int main(){
    char *c="#include<stdio.h> char name[] = \"Jacob Stinson\"; int main(){char *c=%c%s%c; prinf(c,34,c,34);}";
printf(c,34,c,34);
}

I need to include the backslash before the " in the string in order to properly print out line 3, however, when I print out *c, I want those backslashes to be present, as to correctly copy the source code. Currently it omits the backslashes from the output.

Wanted to see if anyone knows how to go about doing this.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jacob Stinson
  • 181
  • 1
  • 16

1 Answers1

0

As the compiler interprets escape sequences in only one direction (deescaping them) I think there's no possibility to include an escape sequence in the code and make it appear as such in the listing. The compiler will always eliminate one of the backslashes on input of the source file, making it appear different on output. The printf uses %s format to allow for the recursive part of the problem and allow you to shelf print, and, as you have guessed correctly, you have to use integer versions of delimiting chars for the " delimiting chars. Why to use %c to be able to delimit the strings in your program if there's an alternative method to include escape sequences? By the same reason, I was not able to include any end of line delimiter, so I wrote the same problem in one line (without using the #include <stdio.h> line) My solution was a one line (without the final end of line.)

Luis Colorado
  • 10,974
  • 1
  • 16
  • 31