Solved

Identify a the beginning of a line and Line Counting

Posted on 2003-11-17
8
243 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 345 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

Independent Software Vendors: 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

Suggested Solutions

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…
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…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

735 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