-6
\$\begingroup\$

You have to write a program that will count all the characters in specified source file so that people entering a code golf competition can see their score. You do not need to ignore comments (it is code golf) in your program but newlines should be counted as a character. The number of characters must be printed to stdout. Shortest code wins!

Example in python:

import sys

try:
    content = open(sys.argv[1], "r").read()
except IndexError, e:
    print("No file specified")
    sys.exit(1)
except IOError, e:
    print("File not found")
    sys.exit(1)

count = 0
for i in list(content):
    if(i!=''):
        count+=1

print(str(count)+" characters long")

Note: you cannot use the bash command wc -c.

\$\endgroup\$

closed as too broad by Doorknob, devnull, TheDoctor, Digital Trauma, user80551 Mar 30 '14 at 7:35

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ 5 chars in bash. wc -c. This is trivial. \$\endgroup\$ – undergroundmonorail Mar 29 '14 at 21:45
  • 7
    \$\begingroup\$ "Note: you cannot use the bash command wc -c." You can't fix a broken problem by banning one example of why it's so broken. \$\endgroup\$ – undergroundmonorail Mar 29 '14 at 21:50
  • 1
    \$\begingroup\$ Question seems trivial. Also banning 'bash' while not banning the other '*sh' languages is essentially pointless. \$\endgroup\$ – Kaya Mar 29 '14 at 22:18
  • \$\begingroup\$ In the future, you might want to run your questions by the sandbox to get help ironing out any problems. \$\endgroup\$ – undergroundmonorail Mar 29 '14 at 23:05
2
\$\begingroup\$

Dash, 18

tr \\0-ÿ \\n|wc -l

Reads from STDIN. Doesn't use wc -c or Bash.

\$\endgroup\$
4
\$\begingroup\$

bash+coreutils, 7 chars

stat $1
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.