?
Solved

Identify a the beginning of a line and Line Counting

Posted on 2003-11-17
8
Medium Priority
?
248 Views
Last Modified: 2010-04-15
I was wondering that If I had an essay that I wanted to create a program to display the essay in portions of 20 lines.  How would I Indentigy the beginning of a line, Count 20 lines of the essay, and tell the user to press any key to continue reading the next 20 lines.  
0
Comment
Question by:teamklimax
[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
  • 3
  • 2
8 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9769284
Hi teamklimax,

on *nix

fp = popen ( "more", "w" );
infile = fopen ( "inputfile", "r");

while ( fgets ( buffer, BUF_SIZE, infile ) != NULL )
   fputs ( buffer, fp );

Cheers!
Sunny:o)
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9769285
Hi teamklimax,

on *nix

fp = popen ( "more", "w" );
infile = fopen ( "inputfile", "r");

while ( fgets ( buffer, BUF_SIZE, infile ) != NULL )
   fputs ( buffer, fp );

Cheers!
Sunny:o)
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 1380 total points
ID: 9769321
on windows, you have _popen in place of popen but I am not sure how good it is ...
what you can however do is something like

infile = fopen ( "inputfile", "r");

while ( fgets ( buffer, BUF_SIZE, infile ) != NULL )
{
            for ( i = 0; i < 20; i++ )
            {
                      puts ( buffer );
                      if ( fgets ( buffer, BUF_SIZE, infile ) == NULL )
                                 break;
             }
             if ( feof ( infile ) )
                     break;
             getch ();
}

this will be portable code ... however there is still an issue...
how do you know that terminal will have 20 lines and not more or less than that ? The kind of method I listed in my first post will be more effective in taking care of such issues
0
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!

 

Expert Comment

by:not_an_xpert
ID: 9769342
in windows _popen  wrks only for a console application.. for those fancy forms with MFC n all it doesnt work ..
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 9770629

Hi teamklimax,

You asked this same question yesterday at this link:

http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20800948.html



Kent
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 10382923

Hi Sunny,

Duplicate question...  Delete/no refund.


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

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…
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 and use pointers in the C programming language.
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.
Suggested Courses

743 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