/* mcPj004E3.c */ /* Real World Application of fileReader.c continues */ /* From old days, here is a note of progress. * mcPj004A.c << Sample 10.04 * mcPj004B.c << Example fscanf(), Screen access. * mcPj004C.c My first successful FileAccess. One word only. * It seems for me a compiling set of libraries were crucial. * OR, in PC's C, I didn't need #include, and * this could be the reason. * mcPj004D.c My second successful FileAccess. One line only. * mcPj004E.c This one, my third successful FileAccess. Whole text. */ /* Now, finally, this program works completely parallel with PC's * (Borland C) file access. * One thing I am getting clear is about NULL. NULL means '0' (zero) * and it is only applicable to the Pointer, not to Arrey nor Variable. */ /* (2004-12-23) One page of explanation fits about 23 lines or around. * So, this naration display is designed for about 23 lines each. * This is a combination of Text-read (printf()) on Screen, and * waiting a user's input (scanf()) as I did in PC C-codes. * It works well. Now it is working at exact 20 lines. * In PC version, I used 'clrscr()' to clean up the page for the next * page, but I didn't see it. I mean I don't see 'conio.h' here. */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { FILE *fp; char line[256], uType[8]; int i; *line=0; i=0; fp=fopen("2_Ref", "r"); /* Read all lines from the file stream pointing to "Ref.txt" */ /* from i=0 to i=22 */ do{ printf("%s", line); i++; }while( (fgets(line, 256, fp))!=NULL && i<=22 ); printf("Type a key then [return] : "); scanf( "%s", &uType); /* from i=23 to i=45 */ printf("\n"); do{ printf("%s", line); i++; }while( (fgets(line, 256, fp))!=NULL && i<=45 ); /* plus 23 */ printf("END of \"2_Introduction\". "); // scanf( "%s", &uType); /* from i=46 to i=68 * printf("\n"); * do{ * printf("%s", line); * i++; * }while( (fgets(line, 256, fp))!=NULL && i<=68 ); * printf("Type a key then [return] : "); * scanf( "%s", &uType); * * * from i=69 to i=91 * printf("\n"); * do{ * printf("%s", line); * i++; * }while( (fgets(line, 256, fp))!=NULL && i<=91 ); * printf("Type a key then [return] : "); * scanf( "%s", &uType); */ fclose(fp); return 0; }