?
Solved

Decalaring a Certain nmber of lines

Posted on 2003-11-03
3
Medium Priority
?
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 46

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 46

Accepted Solution

by:
Kent Olsen earned 1500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

765 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