Solved

Decalaring a Certain nmber of lines

Posted on 2003-11-03
3
190 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:Kdo
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:
Kdo 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now