Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Decalaring a Certain nmber of lines

Posted on 2003-11-03
3
Medium Priority
?
197 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

Technology Partners: 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

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…
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 and use structures 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.

610 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