Solved

Identify a the beginning of a line and Line Counting

Posted on 2003-11-17
8
236 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
Why are Office 365 signatures so complicated?

Trying to setup transport rules for Office 365 email signatures and can’t quite figure it out? Having to test the signature over and over? Make things simple by using Exclaimer Cloud - Signatures for Office 365.

 

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

Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

Question has a verified solution.

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

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops 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.

910 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

20 Experts available now in Live!

Get 1:1 Help Now