How to find inodes within a file?

C++ coding help...create a program that opens a file and find and show the words that have the most letters?

  • I have to create a program that opens a file and I have to find and show the words that have the most letters. I got the file to open but I can't figure out how to count the letters. I think I have to have a for loop in order to move through the contents of the file but I can't get it to work properly.This is what I have done but I am not sure about the what to put in the loop. Also, the contents of the file look like this: 12,Apple,fruit,dog,cat,car,tree,Pill,f… I know I have to use the loop to count the commas but I don't know how. Can anyone help me with this? #include <iostream> #include <fstream> using namespace std; int main() { const int SIZE = 60000; char name[SIZE]; char *info ; string word; int count, i_word, i_count; count = 0; ifstream inFile; inFile.open ("lab04Small.dat"); if (!inFile) { cout<< " Shame on you, you broke the file. Actually, the file cannnot be found"; return -1; } inFile.getline(name, SIZE); info = new char[SIZE] ; int cWords( char *letters ); { char cWords( *info); cout<< name <<endl; inFile.getline(name, SIZE, '\n'); //inFile>>word; while(!inFile.eof()) { for(count=0; count <= SIZE; count++) count << name[count]; if(count= ',') count = } } cout << "The word or words with the most letters is " << count <<endl; return 0; }

  • Answer:

    Inside your while loop for going through the file you need another loop either a while or for loop to count characters between commas. Have a variable to contain the largest count and a variable to contain the current count (between commas). When a comma is encountered compare the current to the largest (init the largest to zero) and put the characters in a variable so you can keep track of the word.

sum_one at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.