home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!ferkel.ucsb.edu!taco!dwthoma1
- From: dwthoma1@eos.ncsu.edu (DAVID W THOMAS)
- Subject: Re: Better way to find out the number of lines in a file
- Message-ID: <1992Jul31.045401.11291@ncsu.edu>
- Originator: dwthoma1@c00081-100lez.eos.ncsu.edu
- Lines: 29
- Sender: news@ncsu.edu (USENET News System)
- Reply-To: dwthoma1@eos.ncsu.edu (DAVID W THOMAS)
- Organization: North Carolina State University, Project Eos
- Date: Fri, 31 Jul 1992 04:54:01 GMT
-
-
- I tried e-mail to you, but it bounced.
-
- You can find out the number of _characters_ with the following code, but
- there is no way to count the number of lines except to loop through
- the characters and count which are '\n' characters. All files look
- like data to unix. Unless you store the number of lines at the top or
- in another index file, unix is not going to store it for you.
-
- If your big file has a constant number of characters per line, then
- you could use the following code and divide by the characters per line.
-
-
- #include <stdio.h>
-
- main()
- {
- FILE *fptr;
- int size;
-
- fptr = fopen("big_file", "r");
- fseek(fptr, 0, SEEK_END);
- size = ftell(fptr);
-
- printf("the size is %d\n", size);
- }
-
- David W. Thomas
- dwthoma1@eos.ncsu.edu
-