/* * filer2.c */ #include #define STRLEN 80 // macro: replace STRLEN with 80 int main(void) { FILE * fp; // declare FILE poitner: fp char ch_string[STRLEN]; // delcare char array:ch_string char fname[15]; // declare char array: fname printf("Enter the name of the file to read:"); // prompt for input scanf("%s", fname); // read from stdin, interpret as string // assign to char array fname if( (fp=fopen(fname, "r")) == NULL ) // open handle to file, for reading // assign handle address to file pointer fp // If the address is NULL, // do block { printf("Can't open file $s\n", fname); // print error to stdout return(1); // return 1 to calling program } while(fgets(ch_string, STRLEN, fp) ) // read string from file handle at fp, until '\0' // assign to char array ch_string, // max of STRLEN elements // while line is not NULL { printf("%s", ch_string); // print contents of array ch_string, intrepret as string } fclose(fp); // close file handle return 0; // return 0 to calling program }