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,tre e,Pill
I know I have to use the loop to count the commas but I don't know how. Can anyone help me with this or even better, am I on the right track?
#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.da t");
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.e of())
{
for(count=0; count <= SIZE; count++)
count << name[count];
if(count= ',')
}
}
cout << "The word or words with the most letters is " << count <<endl;
return 0;
}
12,Apple,fruit, dog,cat,car,tre e,Pill
I know I have to use the loop to count the commas but I don't know how. Can anyone help me with this or even better, am I on the right track?
#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.da t");
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.e of())
{
for(count=0; count <= SIZE; count++)
count << name[count];
if(count= ',')
}
}
cout << "The word or words with the most letters is " << count <<endl;
return 0;
}
Comment