Results 1 to 6 of 6
  1. #1
    Reine is offline Member
    Join Date
    Sep 2011
    Posts
    12
    Rep Power
    0

    Default Counting characters

    Hi guys. So I'm writing a programme which counts characters from an external text file. My lecturer provided a small guideline to do it but there is an error somewhere which i'm having difficulty finding. can you help me please?



    TextFile inName = new TextFile (true, "data.txt");
    int in;
    int counter = 0;
    while (!inFile.eof())
    {
    in = inFile.readInt();
    counter = counter + 1;
    }

  2. #2
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Counting characters

    No one knows the class "TextFile".....
    Which error?
    What is inFile ? Do you mean inName ?

  3. #3
    Reine is offline Member
    Join Date
    Sep 2011
    Posts
    12
    Rep Power
    0

    Default Re: Counting characters

    Thanks for the reply! To be completely honest, I'm not quite sure. I've only done java for a couple of weeks now and after I changed inFile to inName, the only error message I got was

    Counter.java:9: error: cannot find symbol
    while (!inFile.eof())
    ^
    symbol: variable inFile
    location: class Counter
    1 error

    Got an idea what is going on?

  4. #4
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Counting characters

    You used two inFile`s in your code...change both :) Or change the first line :D

  5. #5
    Reine is offline Member
    Join Date
    Sep 2011
    Posts
    12
    Rep Power
    0

    Default Re: Counting characters

    ah thanks a lot! :)

  6. #6
    Reine is offline Member
    Join Date
    Sep 2011
    Posts
    12
    Rep Power
    0

    Default Re: Counting characters

    There's another thing actually! Now my programme says
    error: "" is not a legal integer
    Do i need to end the text document with a special character to stop the reader?

Similar Threads

  1. Counting words
    By Wasley in forum New To Java
    Replies: 9
    Last Post: 01-30-2011, 10:57 PM
  2. Counting help
    By jksmithson in forum New To Java
    Replies: 1
    Last Post: 11-06-2009, 02:43 AM
  3. Recursive Counting
    By zlwilly in forum New To Java
    Replies: 1
    Last Post: 01-29-2009, 08:42 PM
  4. Counting characters
    By Tiff89 in forum New To Java
    Replies: 10
    Last Post: 12-12-2008, 09:21 AM
  5. Need help with counting letters
    By mrdestroy in forum New To Java
    Replies: 15
    Last Post: 10-22-2008, 01:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •