C Online Compiler
Example: C Program to Display its own Source Code as Output
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C program to Display its own Source Code as Output #include <stdio.h> // It's the main function of the program int main() { FILE *file_pointer; int program_character; // Step-1 Open the current file as an input file_pointer = fopen(__FILE__,"r"); // Step-2 Read character's from the input file & Then display these characters on time do { program_character = getc(file_pointer); putchar(program_character); } while (program_character != EOF); // Loop will stop until the end of the file is reached // Step-3 Close the input file fclose(file_pointer); printf("\n"); return 0; }
Output
Clear
ADVERTISEMENTS