Solved

Decalaring a Certain nmber of lines

Posted on 2003-11-03
3
189 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops 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.

706 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

14 Experts available now in Live!

Get 1:1 Help Now