Created
February 1, 2013 23:19
-
-
Save tlehman/4694863 to your computer and use it in GitHub Desktop.
Program that prints out its own source code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fcntl.h> | |
#include <stdio.h> | |
#define MAX 1024 | |
int main(int argc, char *argv[]) { | |
int fd; | |
char buf[MAX]; | |
fd = open("self-rep.c", O_RDONLY); | |
while( read(fd, buf, MAX) > 0 ) { | |
printf("%s", buf); | |
} | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment