Parent Directory
|
Revision Log
Added scriptable wc
// wc.c // A script friendly version of wc // Copyright 2006 Jeremy Grosser // synack@csh.rit.edu #include <stdio.h> #include <stdlib.h> #include <errno.h> int main(int argc, char *argv[]) { char *buf; FILE *fd; int len, i, count; if(argc < 2) { fprintf(stderr, "Usage: %s <filename>\n", argv[0]); exit(0); } fd = fopen(argv[1], "r"); // Get the file size fseek(fd, 0, SEEK_END); len = (int)ftell(fd); fseek(fd, 0, SEEK_SET); buf = malloc(len); fread(buf, len, 1, fd); fclose(fd); for(i = 0; i < len; i++) { if(buf[i] == '\n') { count++; } } fprintf(stdout, "%i\n", count); return 0; }
| synack at csh.rit.edu | ViewVC Help |
| Powered by ViewVC 1.0.0 |