This is piece of my code
std::string s;
getline(cin, s);
std::cin.clear();
s.erase(std::remove_if(s.begin(), s.end(), my_predicate), s.end());
char *str1 = (char*)malloc(sizeof(char)*(s.size()+1));
const int length = s.length();
for(int i=0; i < length; ++i)
{
s[i] = std::tolower(s[i]);
}
strncpy(str1,s.c_str(), s.length()+1);
printf("\n");
The problem is if I do not print \n the code crashes. I have tried memcpy and strdup also but to no avail. Is there any error or any way to get rid of this ????