#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "openFile.h"
#include "../readCharacter/readCharacter.h"

int 
openFile (cmd_args args)
{
  if (args.arg0 == 2)
    {
      args.fp = fopen(args.arg1, "r");
      strcpy(args.filename, args.arg1);
    }
  else
    {
      args.fp = fopen(args.arg2, "r");
      strcpy(args.filename, args.arg2);
    }
  
  /* printf("%s\n", args.filename); */
  
  if (args.fp == NULL)
    {
      fprintf(stderr, "No such file or directory\n");
      exit(INVALID_FILE_OR_ARG);
    }
  else
    {
      /* printf("File found\n"); */
      readCharacter(args);
    }
  return 0;
}
