I am trying to print missing alphabets in given string. The input specification is to end string input if user enter "endpara". With my current code it is storing only first word in string even though input is terminating after entering 'endpara'. (for eg. if I enter "fox jumps over a. endpara" , it is storing only fox in string. How can I store entire string before endpara?
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
const int MAX_CHAR = 26;
string missingChars(string str)
{
bool present[MAX_CHAR] = {false};
for (int i=0; i<str.length(); i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
present[str[i]-'a'] = true;
else if (str[i] >= 'A' && str[i] <= 'Z')
present[str[i]-'A'] = true;
}
string res = "";
for (int i=0; i<MAX_CHAR; i++) {
if (present[i] == false)
res.push_back((char)(i+'a'));}
for(int i=0;i<=res.length();i++) {
if(res[i]>=97 && res[i]<=122)
{
res[i]=res[i]-32;
}
}
return res;
}
int main()
{
string input;
string line;
while (getline(cin, input) && input != "endpara") {
istringstream is(input);
is>>input;
if(missingChars(input)== ""){
cout<<"NONE";
}
else{
cout<<missingChars(input);
}
}
return 0;
}