Public feed #890667

Mine

public text v1 · immutable
Raw Edit
·published 2008-02-03 22:55 UTC
rendered paste body
#include <stdio.h>
#include <string.h>

int 
main(int argc, char **argv)
{
	FILE *stream = NULL;
	char *file_name = "google.txt";
	char buf[BUFSIZ] = {0};

        int test;
	int counter;
	int new_line;
	int x;
        size_t bytes_read;	

	counter = new_line = test = bytes_read = 0;

	stream = fopen(file_name, "rb");

	if (stream == NULL) {
		fprintf(stderr, "ERROR: Unable to open %s\n", file_name);
	}

	bytes_read = fread(buf, sizeof(buf[0]), sizeof(buf)/sizeof(buf[0]), stream);
	(void)printf("%d\n", (int)bytes_read);

	while ( bytes_read > 0 ) {
	   for (x = 0; x <= bytes_read; x++) {
	       if(buf[x] == '\n')
	          counter++;
	   }
	   bzero(buf, sizeof(buf));
	   bytes_read = fread(buf, sizeof(buf[0]), sizeof(buf)/sizeof(buf[0]), stream);
	}

	fclose(stream);

	(void)printf("There Are %d lines\n",counter);
	return 0;

}