Write a program that reads in a sentence of up to 100 characters and
outputs the sentence with spacing corrected and with letters corrected
for capitalization. In other words, in the output sentence, all strings of
two or more blanks should be compressed to a single blank. The sentence
should start with an uppercase letter but should contain no other uppercase letters. Do not worry about proper names; if their first letters
Are changed to lowercase, that is acceptable. Treat a line break as if it were
a blank, in the sense that a line break and any number of blanks are
compressed to a single blank. Assume that the sentence ends with a
period and contains no other periods. For example, the input
the Answer to life, the Universe, and everything
IS 42.
should produce the following output:
The answer to life, the universe, and everything is 42.
#include <iostream>
#include<cstring>
using namespace std;
int main()
{ char arr[100];
int len=0, j=0;
string str;
cout<<"Enter string:"<<endl;
getline(cin, str);
len = str.length();
char res[100];
strcpy(arr, str.c_str());
for(int i = 0; i<len; i++){
if(arr[i]==' ' && arr[i+1]==' ')
continue;
if(arr[i]>=65 && arr[i]<=90){
res[j++]=arr[i]+32;
}
else{
res[j++]=arr[i];
}
}
res[0]=res[0]-32;
cout<<"Output string;"<<endl;
cout<<endl;
for(int i=0;i<j;i++)
cout<<res[i];
return 0;
}