[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Identify a the beginning of a line and Line Counting

Posted on 2003-11-17
8
Medium Priority
?
255 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
6 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
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!

 

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 46

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 46

Expert Comment

by:Kent Olsen
ID: 10382923

Hi Sunny,

Duplicate question...  Delete/no refund.


Kent
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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 and use switch statements in the C programming language.
Suggested Courses
Course of the Month17 days, 17 hours left to enroll

830 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