/* * filer1.c */ #include int main(void) { FILE * fp; // delcare file pointer: fp char cc; // declare char: cc char fname[15]; // delcare char array: fname printf("Enter a name of an existing file to read: "); // prompt for input scanf("%s", fname ); // read string, assign to char array fname getchar(); // clear newline form input buffer fp=fopen(fname, "r"); // initialize file poitner to file, as read-only if(fp == NULL) // if fp points to NULL address, do block { printf("Can't open file %s\n", fname);// print error return 1 ; } while( (cc=fgetc(fp)) != EOF) // read character from file handle at fp // assign value to cc // while not EOF // do block { putchar(cc); // print content of cc to stdout. } fclose(fp); // close file handle at fp return 0; }