
给定的任务是打印编写的C程序本身。
我们必须编写一个C程序,它将打印自身。因此,我们可以在C中使用文件系统来打印我们编写代码的文件的内容,就像我们在“code 1.c”文件中编写代码一样,所以我们以读模式打开文件,并读取文件的所有内容,并将结果打印在输出屏幕上。
但是,在以读模式打开文件之前,我们必须知道我们正在编写代码的文件的名称。因此,我们可以使用“__FILE__”这个宏,默认情况下返回当前文件的路径。
“__FILE__”宏的示例
#includeint main() { printf(“%s”, __FILE__); }
上述程序将打印代码所在文件的源代码
Ke361是一个开源的淘宝客系统,基于最新的ThinkPHP3.2版本开发,提供更方便、更安全的WEB应用开发体验,采用了全新的架构设计和命名空间机制, 融合了模块化、驱动化和插件化的设计理念于一体,以帮助想做淘宝客而技术水平不高的朋友。突破了传统淘宝客程序对自动采集商品收费的模式,该程序的自动 采集模块对于所有人开放,代码不加密,方便大家修改。集成淘点金组件,自动转换淘宝链接为淘宝客推广链接。K
宏__FILE__返回一个字符串,其中包含当前程序的路径,它被提及的位置。
因此,当我们将其合并到文件系统中以以只读模式打开代码所在的当前文件时,我们可以像这样做-
fopen(__FILE__, "r");
算法
Start
Step 1-> In function int main(void)
Declare a character c
Open a FILE “file” “__FILE__” in read mode
Loop do-while c != End Of File
Set c = fgetc(file)
putchar(c)
Close the file “file”
Stop示例
#includeint main(void) { // to print the source code char c; // __FILE__ gets the location // of the current C program file FILE *file = fopen(__FILE__, "r"); do { //printing the contents //of the file c = fgetc(file); putchar(c); } while (c != EOF); fclose(file); return 0; }
输出
#includeint main(void) { // to print the source code char c; // __FILE__ gets the location // of the current C program file FILE *file = fopen(__FILE__, "r"); do { //printing the contents //of the file c = fgetc(file); putchar(c); } while (c != EOF); fclose(file); return 0; }










