File IO

#include <stdio.h>

int main(int argc, char *argv[])
{
    FILE *fp;

    if(argc == 1)
    {
        fprintf(stderr, "Please enter a file name\n");
        return 1;
    }

    else if(argc == 2)
    {
        if((fp = fopen(*++argv, "r")) == NULL)
        {
            fprintf(stderr, "Can't open %s\n", *argv);
            return 1;
        }
        else
        {
            printf("Opening %s...\n", *argv);
            fclose(fp);
        }
    }

    return 0;
}

FILE is used to declare file pointers, in this case *fp. fopen has two arguments, the first being the filename and the second being the opening mode. It returns NULL on an error opening the file. Then we can close the file by using fclose(fp).