Solved

Identify a the beginning of a line and Line Counting

Posted on 2003-11-17
8
235 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
  • 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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:Kdo
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:Kdo
ID: 10382923

Hi Sunny,

Duplicate question...  Delete/no refund.


Kent
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

708 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

17 Experts available now in Live!

Get 1:1 Help Now