刚看到一个输出自身代码的程序
main(){char *c="main(){char *c=%c%s%c;printf(c,34,c,34);}";printf(c,34,c,34);}谁能解释一下最后一句printf(c,34,c,34),谢谢。。
c is a format string.
try following code snippet:
===========================
/*---------------------------------------------------------------------------
File name: main.c
Author: HJin (email: fish_sea_bird [at] yahoo [dot] com )
Created on: 9/21/2007 02:56:54
Environment: WinXPSP2 En Pro + VS2005 v8.0.50727.762
Modification history:
===========================================================================
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
int c;
char ch;
FILE* fp = fopen(__FILE__, "r");
if(!fp)
{
printf("cannot open file.\n");
exit(1);
}
c=23*45;
while( (ch=fgetc(fp)) != EOF )
{
putchar(ch);
}
fclose(fp);
return 0;
}