Solved

calculationg lines by \n and not word wrap?

Posted on 2004-09-20
2
214 Views
Last Modified: 2012-05-05
I am just wondering if there is an easier way to calculate lines based on (enter key) \n. One one to do is to go trhough each char and find how many \n are there in the file. The statement i am using is:
while ( fgets( line, LINELEN, fp ) )
{ /* more input */
              total_lines++; /* count it */  
}

thanks
0
Comment
Question by:Carl3003
2 Comments
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 30 total points
ID: 12103058
system( "wc -l" + fname );
0
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 20 total points
ID: 12103133
Carl,

There are arguably quicker ways but apart from breaking out into system calls (which is then immediately non-portable) I cant think of any easier ones. That doesnt mean that greg's idea is wrong!! You just need to be aware of its limitations.

Other methods will use essentially exactly the same process of counting the 'newline' codes, just in different forms.

Paul
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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 how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files 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

18 Experts available now in Live!

Get 1:1 Help Now