Mail Archives: djgpp/1998/11/21/12:12:47
This is a multi-part message in MIME format.
------=_NextPart_000_0039_01BE153E.42DD2F20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Try the following attachment...
Hope this helps
Steve
-----Original Message-----
From: Nate Eldredge <nate AT cartsys DOT com>
Newsgroups: comp.os.msdos.djgpp
To: djgpp AT delorie DOT com <djgpp AT delorie DOT com>
Date: Friday, November 20, 1998 8:25 PM
Subject: Re: Line Checking..
>Jeff Johnson wrote:
>>
>> How Do I Chech To See How Mine Lines (Up/Down) A File Is?
>>
>> Like, say,
>>
>> --out.dat--
>> 1
>> 2
>> 3
>> 4
>> ----------
>>
>> and i want my prog to tell me that there are 4 lines in that file, how do
i
>> do that??
>
>Btw, you are reinventing the wheel.  Get the textutils and look at the
>`-l' option to `wc'.
>--
>
>Nate Eldredge
>nate AT cartsys DOT com
------=_NextPart_000_0039_01BE153E.42DD2F20
Content-Type: application/octet-stream;
	name="List.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="List.c"
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[])
{
	int line;
	char buffer[256];
	FILE *fp;
	if(argc<2) {
		fprintf(stderr,"\nProper Usage is: ");
		fprintf(stderr,"\n\nLIST filename.ext\n");
		exit(1);
	}
	if((fp=fopen(argv[1],"r"))==NULL) {
		fprintf(stderr,"Error opening file, %s!", argv[1]);
		exit(1);
	}
	line=1;
	while(fgets(buffer,256,fp) !=NULL)
		fprintf(stdout,"%4d:\t%s",line++,buffer);
	fclose(fp);
	printf("\n\nThe total number of lines are %d",line-1);
	return 0;
}
------=_NextPart_000_0039_01BE153E.42DD2F20--
- Raw text -