this is the code but i have some questions on it !!?
Code:
#include <stdio.h>#include <string.h>
#define LINE_SIZE 80 /* # characters per line. */
#define SCREEN_LINES 24 /* # lines per screen. */
/* This function displays the contents of a text file
* one screenful at a time.
* It returns 0 if successful and -1 otherwise.
*/
int DisplayFile(char FileName[])
{
FILE *fp;
char LineBuffer[LINE_SIZE], *ptr;
int LineCount = 0;
fp = fopen(FileName, "r");
if (fp == NULL) {
printf("File '%s' not found.\n", FileName);
return -1;
}
/* Display the text one screen at a time */
do {
/* Read and display a single line */
ptr = fgets(LineBuffer, LINE_SIZE, fp);
if (ptr != NULL) {
printf("%s", LineBuffer); /* Display the line */
LineCount++;
}
/* Have we displayed a screenful yet (or finished) ? */
if (LineCount == (SCREEN_LINES - 1) || ptr == NULL) {
printf("\n\t\tPress RETURN to continue");
/* Wait for user to press ENTER before continuing */
while (getchar() != '\n')
; /* do nothing */
LineCount = 0; /* reset counter */
}
} while (ptr != NULL);
return 0;
}
int main(void)
{
int result;
result = DisplayFile("sample.txt");
return result;
}
i dont get this part ???????????
Code:
do {/* Read and display a single line */
ptr = fgets(LineBuffer, LINE_SIZE, fp);
if (ptr != NULL) {
printf("%s", LineBuffer); /* Display the line */
LineCount++;
}