character count from file?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: character count from file?

  1. #1
    Join Date
    Oct 2004
    Posts
    34

    Question character count from file?

    The file is attached "ParsingTextFileCount.java file.dat "
    It takes an argument via command line. It reads from the file, the words, number of lines, but I can not get the character count to increment to give me the total characters in the file?

    Program produces word count and line count fine, but need character count.

    if ((charcount = frs.read()) != -1){
    charcount++;
    }
    Thanks......
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2004
    Location
    Indianapolis, IN
    Posts
    424
    Aren't you overwriting your character count each time you do a frs.read()?

    Shouldn't you be doing something like

    Code:
          if ((rv = frs.read()) != -1)
          {
    	  charcount = charcount + rv;
          }
    Just a guess....

    Brad!
    -------------------------------------------------
    Bradley L. Jones
    Author, and more.
    QuinStreet / Internet.com
    (Developer.com, CodeGuru.com, DevX, jGuru, and more!)

    -------------------------------------------------

  3. #3
    Join Date
    Oct 2004
    Posts
    34

    character count from file?

    Yes, that is correct must have typed it in wrong...the code worked using a while loop, but now I do not get the line or word count? I have attached a txt file of the updated version. Any way to set this up so I can get word,line and char count?

    Now getting charcount but not others?
    while ((rv = frs.read()) != -1){
    charcount++;



    Thanks
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center