Hi
I am making a program that reads a string, when it finds a '.' character it changes the next character after the '.' to uppercase.
My problem is, I am trying to take a string with 5 arrays (string line[5]), & extract the 1st character of line[0], then the 1st character of line[1] and so on. But I dont know the correct way to do it?
input file (info.txt) contents:
i went to the zoo. i love cheese. how are you. what is your name. nice to meet you.
Here is my code, as you can see I dont know the correct syntax to do what I want in function capitalise.
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void capitalise(string line_array[]);
int main()
{
ifstream infile;
string line_array[5];
infile.open("info.txt");
if (!infile)
{
cout << "Failed to open file";
return 0;
}
for (int i = 0; i < 5; i++)
{
getline(infile, line_array[i], '.');
}
infile.close();
capitalise(line_array);
return 0;
}
void capitalise(string line_array[])
{
char first_letter[5];
for (int i = 0; i < 5; i++)
{
line_array >> cin.ignore(100, ' ');
first_letter[i] = line_array[i];
}
for (int j = 0; j < 5; j++)
{
if ( first_letter[j] != toupper(first_letter[j]) )
first_letter[j] = toupper(first_letter[j]);
}
}