荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: Version (Who makes history and why), 信区: Program
标  题:  一个可以输出自己的C程序(1
发信站: 荔园晨风BBS站 (Wed Mar 19 16:08:28 2003), 站内信件

/*
 为了便于大家看懂这段程序, 我已经进行了风格处理, 要查看程
 序本身的样子请大家把程序的运行结果重定向到一个文本文件中
*/
#include <stdio.h>
char *program = "void escape(char *s){int i=0;while(s[i]!=0){if(s[i]==0x40)s
[i]=0x22;if(s[i]==0x24)s[i]=0x40;if(s[i]==0x26)s[i]=0x0A;if(s[i]==0x5E)s[i]=
0x26;i++;}} void main(void){char *formatstr=@#include <stdio.h>^char *progra
m=$%s$;@;escape(formatstr);printf(formatstr,program);escape(program);puts(pr
ogram);}";
/*
 escape function
*/
void escape(char *s)
{
 int i = 0;
 while (s[i] != 0)
 {
  if (s[i] == 0x40)  // '@'
   s[i] = 0x22;  // '"'
  if (s[i] == 0x24)  // '$'
   s[i] = 0x40;  // '@'
  if (s[i] == 0x26)  // '&'
   s[i] = 0x0A;  // '\n'
  if (s[i] == 0x5E)  // '^'
   s[i] = 0x26;  // '&'
  i++;
 }
}
/*
 main function
*/
void main(void)
{
 char *formatstr = "#include <stdio.h>&char *program=@%s@;";
 escape(formatstr);
 printf(formatstr, program);
 escape(program);
 puts(program);
}

   s[i] = 0x26;  // '&'
  i++;
 }
}
/*
 main function
*/
void main(void)
{
 char *formatstr = "#include <stdio.h>&char *program=@%s@;";
 escape(formatstr);
 printf(formatstr, program);
 escape(program);
 puts(program);
}

--
                      *
          *                                  *
                          *             *
                      no more to say
                  ★     just wish you   ★
                            good luck

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.1.50]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店