Here's an example program:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
This program will take a dir as the first arg
and a file name as the second arg and then
open the file and print it to stdout.
*/
int main(int argc, char *argv[])
{
int c = 0;
char szSlash[] = "/";
char *szFile = NULL;
FILE *f = NULL;
if(argc < 3)
{
printf("Usage: %s <path> <file>\n", argv[0]);
return 1;
}
szFile = malloc(strlen(argv[1]) + strlen(szSlash) + strlen(argv[2]) + 1);
if(!szFile)
{
printf("Unable to allocate memory...\n");
return 2;
}
strcpy(szFile, argv[1]);
strcat(szFile, szSlash);
strcat(szFile, argv[2]);
f = fopen(szFile, "r");
if(!f)
{
printf("Unable to open file \"%s\"...\n", szFile);
return 3;
}
while((c = fgetc(f)) != EOF)
{
putchar(c);
}
fclose(f);
free(szFile);
return 0;
}
And yes, C is primitive, but extremely powerful.