r/dailyprogrammer • u/rya11111 3 1 • Apr 08 '12
[4/8/2012] Challenge #37 [easy]
write a program that takes
input : a file as an argument
output: counts the total number of lines.
for bonus, also count the number of words in the file.
9
Upvotes
4
u/bob1000bob Apr 08 '12
C++
Compilation
running the source file against the source file gets:
4
u/gjwebber 0 0 Apr 08 '12
Here is my attempt in Pyhon, with bonus:
Thoughts?
4
u/Ttl Apr 08 '12
Ugly python oneliner. Not very pythonic but I liked the challenge of cramming everything in one line:
8
u/[deleted] Apr 08 '12
bash with bonus
:D
1
u/robotfarts Apr 08 '12
You suck! Newline character is platform dependent. :P
2
u/lawlrng_prog Apr 08 '12
Python3. Splits "words" on whitespace. Got to learn about fileinput tho, so that was cool. Works for any number of files given on the command line. :]
Run on itself we get:
2
u/[deleted] Apr 08 '12 edited Apr 08 '12
C++
2
u/eruonna Apr 08 '12
Haskell:
2
u/Steve132 0 1 Apr 08 '12
C++ one-liner. (not including headers and main() )
1
u/thatrandomusername Apr 08 '12
node.js (javascript)
1
u/stevelosh Apr 08 '12
Clojure. I made it a function instead of a full program because command line args are a pain in the ass in Clojure, but it'll also work on URLs so I think that balances it out:
1
u/Daniel110 0 0 Apr 08 '12
python
any input?
1
u/magwhich Apr 08 '12
Did this in python as a regex exercise using python
1
u/theOnliest Apr 09 '12
Perl, with bonus in last 3 lines:
1
u/mazzer Apr 09 '12
Groovy.
There might be a much Groovier way to solve this.
1
u/sanitizeyourhands Apr 09 '12 edited Apr 09 '12
C#:
1
u/mpmagi Apr 09 '12
C++ critiques welcome
include <fstream>
include <iostream>
include <string>
using namespace std;
int main(){ ifstream InputFile; InputFile.open("4812reference.txt"); // Reference item int numOfLines = 0; string line; while(!InputFile.eof()){ getline(InputFile, line); numOfLines++; } cout << numOfLines; cin.get(); return 0; }
1
u/Vectorious Apr 09 '12 edited Sep 18 '25
retire seemly badge vase nail fearless encourage rob dolls aback
This post was mass deleted and anonymized with Redact
1
u/Haruhi_Suzumiya Apr 09 '12
Done in C#.
http://pastebin.com/SYLF2iry
1
u/cooper6581 Apr 10 '12
C99 (quick and dirty):
1
u/V01dK1ng 0 0 Apr 12 '12
C++ with a bonus:
1
u/Intolerable Apr 26 '12
1
u/Sturmi12 May 14 '12
C
1
u/Medicalizawhat May 26 '12
Ruby:
1
u/Should_I_say_this Jul 01 '12