Solved

Decalaring a Certain nmber of lines

Posted on 2003-11-03
3
192 Views
Last Modified: 2010-04-15
i need to know how to read in a ceartin number of lines from a file per screen(page). i have to read in 20 lines per screen
0
Comment
Question by:shorty225
  • 2
3 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 9671349

This is pretty easy.


Read 20 lines from the file (use fgets()) and display them on the screen (use fprintf()).  After displaying line 20, wait for someone to press return (use fgets() or getchar ()) and do it all over again.


Kent
0
 

Author Comment

by:shorty225
ID: 9671528
how do i put fgets in though?
0
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 9671637

Hi shorty,

I'm trying to walk a fine line between helping you and doing your homework.  I'll gladly explain anything about which you have questions and give you whatever knowledge that you need to do your work, but I can't volunteer to go much beyond your questions so that my work doesn't become yours.

If you're working on a unix or linux system, you should me able to enter the command "man fgets" and get the entire help text on fgets() (and several other related fuctions).

Here's a quick example of using fgets():

#include <stdlib.h>
#include <stdio.h>

main ()
{
  FILE *myfile;
  char Buffer[200];

  myfile = fopen ("File.txt", "r");
  if (myfile == NULL)
    fprintf (stderr, "File.txt could not be opened.\n");
  else
  {
    fgets (Buffer, 200, myfile);
    fprintf (stdout, "The first line in the file is :%s\n", Buffer);
    fclose (myfile);
  }
}


Good Luck,
Kent
 
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question