counting number of lines in a file(not home work) 
Author Message
 counting number of lines in a file(not home work)


I would like to know how to count the number of lines in a file
because it is an "extra part" (I'M the only one doing this most likely)
of a Finite Element Class project.

This is not the project just a part that I thought would make a better
program (because I am writing in C and the Prof. writes in fortran, so allocates more
memory then needed).  Also I had a working subroutine that did this (using fgets())
but since I'M no computer programmer (graduate student in Mechanical Engineering)
I thought that there must be a better way.

I believe that in asking for help I have not cheated, since this
has nothing to do with implementation of the finite element  part of the program.

I would never ask some one for the answer to home work or work for that matter.

David cotrell



Thu, 29 Jul 1999 03:00:00 GMT  
 counting number of lines in a file(not home work)

Quote:


> I would like to know how to count the number of lines in a file
> because it is an "extra part" (I'M the only one doing this most likely)
> of a Finite Element Class project.

> I would never ask some one for the answer to home work or work for that matter.

> David cotrell

Just read the file and count '\n' characters.

/* Compile this to lc (line count) */
#include <stdio.h>
int main() {
        int c, i = 0;
        while ((c = getchar()) != EOF)
                if (c == '\n')
                        ++i;
        printf("%d\n", i);
        return 0;

Quote:
}

Now pipe the file you are interested in to this program:
% cat file.typ | lc
If you don't know what cat is, use type.  If you don't know what either
are, read some more..
--

"Everything should be made as simple as possible, but not simpler."
         --Albert Einstein--


Thu, 29 Jul 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. counting number of lines in a file

2. Count number of empty lines in a file ???

3. Looking for Tools witch count the number of lines of my files cpp and comments

4. Counting the number of lines on C#

5. How To Count Number of Executable Lines

6. Challenge - not home WORK

7. How can i count numbers in an int or count characters in a string in the

8. .NET Reference counting not working?

9. Counting and Reading Lines from a File

10. Counting lines in file quick

11. Fastest way to count lines of text in a file

12. Counting and Reading Lines from a File

 

 
Powered by phpBB® Forum Software