home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!almserv!antares!e3ubec
- From: e3ubec@fnma.COM (Blaine Crowther)
- Subject: Re: Looking for "C" Source Line Counter
- Message-ID: <1992Nov23.230453.9874@almserv.uucp>
- Sender: usenet@almserv.uucp
- Nntp-Posting-Host: antares
- Reply-To: e3ubec@fnma.COM
- Organization: Fannie Mae
- References: <1992Nov21.184741.6512@gw.wmich.edu>
- Date: Mon, 23 Nov 1992 23:04:53 GMT
- Lines: 35
-
- If you can't find one try this:
-
- void
- main( int argc, char * argv[])
- {
- #define DELIMITER ';'
-
- int ch,
- line = 0;
-
- FILE * fp;
-
- if( argc != 2)
- fprintf( stderr,"Please input a file name\n");
-
- else if( (fp = fopen( argv[1], "r")) == (FILE *)NULL)
- fprintf( stderr,"File '%s' could not be opened\n",argv[1]);
- else
- {
- while( (ch = getc( fp )) != EOF)
- if( DELIMITER == ch )
- line++;
- fprintf(stdout,"File %s contains %d lines.\n", argv[1], line);
- }
- }
-
- It's ansi , so it should work anywhere. Nothing fancy, it just counts
- semi-colons. If you want all lines, just redefine DELIMITER '\n' for
- new lines.
-
- command line execution would be:
-
- program_name file_name
-
- blaine
-