If possible can I have some assistance with this program?

I've gotten this far but I'm confused on what to do next to get the program to process the letters from the file into the getline.

void input(ifstream& in, int count, string s);

void getline(ifstream& in, string s, int count);

void input(ifstream& in, int count, string s)

{

 count = 0;

 in.open("word_data.txt");

 if (in.fail())

 {

  cout << "Input file did not open correctly" << endl;

 }

 else {

  cout << "opened";

  while (in)

  {

   in >> s;

   count++;

  }

 }

 cout << "" << count << endl;

 in.close();

}

void getline(ifstream& in, string s, int count)

{

 int lower_letter_count = 0;

 int upper_letter_count = 0;

 int space_count = 0;

  for (int i = 0; i < s.length(); i++)

  {

   cout << static_cast<char>(tolower(s[i]));

  }

  cout << endl;

  for (int i = 0; i < s.length(); i++)

  {

   cout << tolower(s[i]) << ' ';

  }

  cout << endl;

  for (int i = 0; i < s.length(); i++)

  {

   cout << s[i] << " " << tolower(s[i]) << endl;

  }

  cout << endl;

  for (int i = 0; i < s.length(); i++)

  {

   if (s[i] >= 'a' && s[i] <= 'z')

    lower_letter_count++;

   else if (s[i] >= 'A' && s[i] <= 'Z')

    upper_letter_count++;

   else if (s[i] == ' ')

    space_count++;

  }

  for (int i = 0; i < 26; i++)

  {

   cout << static_cast<char>(96 + i) << endl;

  }

 cout << " " << lower_letter_count << endl << " " << upper_letter_count << endl << " " << space_count; 

}

int main()

{

 ifstream in;

 string s;

 int count=0;

 input(in, count, s);

 getline(in, s, count);

 return 0;

}

1 Answer

Relevance
  • EddieJ
    Lv 7
    3 weeks ago
    Favorite Answer

    We have to sort of guess exactly what your assignment is.

    There is already a function included with C++ called getline (), but you seem to be reusing the name for your own function.

    Meanwhile, I don't think

    in >> s;

    does what you want it to do.  Are you trying to put the whole file into <s>?

Still have questions? Get your answers by asking now.