6 /* Check that a file exists. */
7 /* If it does, read it into an array and print it out. */
15 /* Helper function, to let us see if a file */
16 /* exists in the current directory. */
17 int fexists(char *fname)
20 fptr = fopen(fname, "r") ;
21 if ( !fptr ) return -1 ; /* File does not exist in dir. */
23 return 0; /* File DOES exist in dir. */
27 /* Helper function to chop newlines off the lines read in. */
28 /* Without this being done, an extra newline is inserted */
29 /* (which is usually not what is wanted). */
32 s[strcspn(s,"\n")] = '\0';
36 /* An array to store the file in. */
37 /* Only 20 lines are read. */
41 /* Read the file into the array of strings. */
42 void readfile(char *fname)
44 int retval = fexists(fname);
48 /* File exists, so open it. */
49 /* We open it in read-write mode so we can */
50 /* append new commands to it. */
52 fptr = fopen(fname, "rw");
56 chop(fgets(myarray[i], 80, fptr) );
61 else puts("Error! File does not exist. \n");