Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
How to make code run differently depending on the platform it is running on?
xarzu - Apr 05 2019 09:17 AM
How do I set a breakpoint in an attached process in visual studio
xarzu - Apr 04 2019 11:47 AM
Recent Blog Entries
Recent Status Updates
- Managed C++
- Visual Basic 4 / 5 / 6
- linked list
- hello world
how to count word?
Posted 06 March 2012 - 07:49 AM
i'm a new member..
may i ask about some coding?
By using the system call read() and write(),
do the coding to calculate the number of characters in the file data.txt
I have try to build the coding but I have no success..
Posted 06 March 2012 - 01:03 PM
Since this is in the Linux Programming and Scripting forum, I'll assume you're scripting using a command line shell. Use the Linux command 'wc' to count various entities in a file (words, letters, lines, etc.)
man page for wc:
NAME wc - print the number of newlines, words, and bytes in files SYNOPSIS wc [OPTION]... [FILE]... DESCRIPTION Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or when FILE is -, read standard input. -c, --bytes print the byte counts -m, --chars print the character counts -l, --lines print the newline counts -L, --max-line-length print the length of the longest line -w, --words print the word counts --help display this help and exit --version output version information and exit
Posted 07 March 2012 - 02:53 AM
your answer seems too advance..
actually, I had not learned that language..
what I need is in C programming language..
can anybody help me?
Posted 07 March 2012 - 06:29 AM
To count characters in a text file, simply open the file to be read, and continue reading characters until you reach End Of File, incrementing a counter variable after each read. At the end, the counter variable will tell you how many characters are in the file.
The library you'll need is:
cstdio (stdio.h) - C++ Reference
Posted 25 March 2015 - 07:11 AM
Let's start with reading and writing files in C, for that Codecall provides a basic tutorial.
Counting is just about measuring the input, and it depends on how did you chose to read the file. Make me know how you did it so we continue.
Posted 03 April 2015 - 06:49 PM
You can easily use functions like fseek() and ftell() to get the number of bytes in the file. So I suppose this is a good time to ask if the file is meant to be read as 1 byte per char, or is the encoding something like UTF-16?
Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer