Skip to content

Instantly share code, notes, and snippets.

@tlehman
Created February 1, 2013 23:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlehman/4694863 to your computer and use it in GitHub Desktop.
Save tlehman/4694863 to your computer and use it in GitHub Desktop.
Program that prints out its own source code
#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