/* Pro08.c */ /* How to access and open an external text file "Ref.txt"? */ /* Please use, FILE *fp (file pointer) and fopen("filename.txt", "r"). */ /* Where "r" stands for read. */ /* getc() gets one character each time. */ /* putc() puts one character each time. */ /* EOF means "End of File". */ #include <stdio.h> int main(void) { int c; FILE *fp; /* Declare file pointer as *fp */ fp=fopen("Ref.txt", "r"); /* Open external "Ref.txt" file */ while((c=getc(fp))!=EOF) /* Read "Ref.txt" by means of file pointer fp */ { putc(c, stdout); /* Echo print out "Ref.txt" on screen */ } fclose(fp); /* Closing file pointer fp */ return 0; }