Welcome Guest! To enable all features please Register.

Notification

Icon
Error

New Topic Post Reply
Are you good at C/C++, If so can you help please?
03009867267499815390
#1 Posted : Wednesday, February 17, 2010 6:42:57 PM(UTC)
Rank: Advanced Member

Joined: 2/16/2010(UTC)
Posts: 30
Points: 90
write a program that asks the user for the name of a file. The program should display the contents of the file on the screen .If the file's contents won't fit on the screen the program should display 24 lines of output at a time, and the pause.Each time the program pauses, it should wait for the user tostrike a key before the next 24 lines are displayed. I

I am so lost please help :(
Sponsor

anil
#2 Posted : Wednesday, February 17, 2010 6:45:15 PM(UTC)
Rank: Advanced Member

Joined: 12/12/2009(UTC)
Posts: 48
Points: 144
Location: India
Here is the program:

Code:
#include <stdio.h> /* required for file operations */
#include <conio.h> /* for clrscr */
#include <dos.h> /* for delay */

FILE *fr; /* declare the file pointer */

main()

{
int n;

int LineCount = 0;
char line[80];
clrscr();

fr = fopen ("FileName.txt", "rt"); /* open the file for reading */
/* FileName.txt is the name of the file */
/* "rt" means open the file for reading text */

while(fgets(line, 80, fr) != NULL)
{
/* get a line, up to 80 chars from fr. done if NULL */
cout>>line;
LineCount++;

if(LineCount == 24)
{
getChar(); //Stops the execution to wait for user input/keypress
LineCount = 0; //Again start counting the number of rows for next screen
}
}
fclose(fr); /* close the file prior to exiting the routine */
} /*of main*/


Hope it helps
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.