C

C seems to be quite a popular choice of language for quine writing, probably for some of the same reasons as it's a popular choice of language for general programming purposes.  But the number of C quines there are already hasn't stopped me writing some of my own.  Here's a nice, fairly compact one to start with:

q(a,b,c){printf("%s%c%s%c%s%c%s%c,%c%s%c,%c%s%c);}",a,34,b,34,c,34,a,34,
34,b,34,34,c,34);}main(){q("q(a,b,c){printf(","%s%c%s%c%s%c%s%c,%c%s%c,
%c%s%c);}",",a,34,b,34,c,34,a,34,34,b,34,34,c,34);}main(){q(");}

Remove the interior line breaks.

Here's a longer one.  This was my attempt at creating a quine that is readable.  A search and replace routine is used to print out the data:

#include <stdio.h>

const char *code[] = { "\
#include <stdio.h>\n\
\n\
const char *code[] = { \"\\", "\
\", \"\\", "\
\" };\n\
\n\
int main(void) {\n\
    int sec;\n\
    const char *pt;\n\
\n\
    for(sec = 0; sec < 3; sec++) {\n\
        if(sec == 2) {\n\
            puts(code[1]);\n\
        }\n\
        else {\n\
            puts(code[sec]);\n\
        }\n\
\n\
        for(pt = code[sec]; *pt != '\\0'; pt++) {\n\
            switch(*pt) {\n\
                case '\\\\': printf(\"\\\\\\\\\"); break;\n\
                case '\"':  printf(\"\\\\\\\"\"); break;\n\
                case '\\n': printf(\"\\\\n\\\\\\n\"); break;\n\
                default:   putchar(*pt);\n\
            }\n\
        }\n\
    }\n\
\n\
    puts(code[2]);\n\
\n\
    return 0;\n\
}" };

int main(void) {
    int sec;
    const char *pt;

    for(sec = 0; sec < 3; sec++) {
        if(sec == 2) {
            puts(code[1]);
        }
        else {
            puts(code[sec]);
        }

        for(pt = code[sec]; *pt != '\0'; pt++) {
            switch(*pt) {
                case '\\': printf("\\\\"); break;
                case '"':  printf("\\\""); break;
                case '\n': printf("\\n\\\n"); break;
                default:   putchar(*pt);
            }
        }
    }

    puts(code[2]);

    return 0;
}

I also experimented with another approach, which does away with backslashes and percent signs to leave only strings that don't need any 'escaping'.  The first string defines the sequence of strings and characters to output:

#include <stdio.h>

char *st[] = {
    "0^^12^`]&]_^`]']'](]'])]']*]_^`]+]'],]']-]_^`].]']/]']0]_^`]1]']2]']3
]_^(^^)2^`*^`+2^``,^```.^``-^```/^`a^`3^a",
    ", ", "}, ch[] = { 34, 10, 44, 9, 125 };", "main()", "char *c;",
    "for(c = st[0]; *c != 0; c++)", "if(*c < 92)", "else",
    "printf(st[*c - 38]);", "putchar(ch[*c - 93]);", "#include <stdio.h>",
    "char st[] =", " {", "return 0;",
}, ch[] = { 34, 10, 44, 9, 125 };

main() {
    char *c;
    for(c = st[0]; *c != 0; c++) {
        if(*c < 92)
            printf(st[*c - 38]);
        else
            putchar(ch[*c - 93]);
    }
    return 0;
}

I tried to keep every line a reasonable length, but didn't quite get there.  But the line break in the first string is the only one you need to remove.

I'll finish with one that won a "Worst abuse of the rules" award in the IOCCC some years ago. Unfortunately it isn't ANSI C compliant, and won't work in all compilers:


Quite short, don't you think?