![]() |
| ||
| word/line/character count in files i did a codig to find the no. of words,no. of characters and no. of lines in a file i was not getting the output, can anyone help me import java.io.*; the file input.dat is |
| ||
| Re: word/line/character count in files The problem is that your Charact method is stuck in the while loop. You obtain the length of the file and state the conditon numChar != -1. Keep in mind what data types are for. They store a copy of the data they accept. Here you're calling f.length() and placing it in numChar (once). Though I'm not very savvy on files, from what I understand you are only storing the file's (current) length once in numChar which means that your while loop will either never execute or execute infinitely since numChar != -1 will be true or false and in your while loop you are not manipulating or changing the data stored in numChar to cause an escape from the loop... therefore an infinite loop. long numChar = f.length(); I made this change and it seemed to work, though I'm not entirely sure it's what you wanted to do-- while(countChar < f.length()){ |
| ||
| Re: word/line/character count in files thanks alex edwards the character part is working along with no. of lines but the no. of words seems to give a wrong output. can you guide me in that thanks in advance |
| ||
| Re: word/line/character count in files Quote:
|
| ||
| Re: word/line/character count in files i modified the count word part and got the desired output /* |
| All times are GMT -4. The time now is 2:19 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC