prntself.c

来自「国外网站上的一些精典的C程序」· C语言 代码 · 共 44 行

C
44
字号
/***  PRNTSELF.C - A program which prints its own source****  public domain demo by Bob Stout*/#include <stdio.h>#include <string.h>#ifdef __WATCOMC__ #pragma off (unreferenced);#endif#ifdef __TURBOC__ #pragma argsused#endifmain(int argc, char *argv[]){      FILE *in;      char fname[13], *ptr;      char line[1024];        /* Nice & roomy   */      /*      ** Get the source name by replacing the executable's COM or EXE with C      */      strcpy(fname, argv[0]);      ptr = strrchr(fname, '.');      strcpy(++ptr, "C");      /*      ** Print its own source      */      if (NULL != (in = fopen(fname, "r")))      {            while (NULL != fgets(line, 1024, in))                  fputs(line, stdprn);            return 0;      }      else  return -1;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?