Tuesday, June 6, 2017

C program that prints itself.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    FILE *fp;
    if ((fp = fopen(__FILE__, "r")) == NULL)
    {
        printf("Error! opening file %s\n", __FILE__);
        exit(1);
    }
    while(!feof(fp))
    {
        printf("%c", fgetc(fp));
    }
    fclose(fp);

    getch();   
    return 0;
}

No comments :