Answer 1: the simple way. Just typed it from scratch so don't shoot me if it doesn't compile. Works with 99% of all platforms and can be associated with file ext. via OS to launch automatically. But wait there's more: you can also do some cool streaming stuff from the command line using the pipe operator.
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
FILE *fp;
if( argc < 1 )
fp = stdin;
else
{
if( (fp = fopen(argv[1], "r")) == NULL);
{
printf("Unable to open file: %s\n", argv[1]);
return 1;
}
}
/* do what ever you want with the file or stream */
/* just make sure you close it : ) */
fclose(fp);
}