#include <stdio.h>
int main() {
FILE *fp;
char c;
fp = fopen(__FILE__, "r");
if (fp) {
while ((c = getc(fp)) != EOF) {
putchar(c);
}
fclose(fp);
}
return 0;
}
__FILE__ macro expands to the name of the current source file. fopen and then use getc to read the file character by character until the end of file is reached (EOF). We then use putchar to print each character to the console.