Hi, I created a program in C++ that remove commas (') from a given integer. i.e. 2,00,00 would return 20000. I am not using any new space. Here is the program i created
void removeCommas(string& str1,int len)
{
int j=0;
for(int i=0;i<len;i++)
{
if(str1[i] == ',')
continue;
else
{
str1[j] =str1[i];
j++;
}
}
str1[j] = '\0';
}
void main()
{
string str1;
getline(cin,str1);
int i = str1.length();
removeCommas(str1,i);
cout<<"the new string "<<str1<<endl;
}
Here is the result i get : Input : 2,000,00 String length =8 Output = 200000 0 Length = 8
My question is that why does it show the length has 8 in output and shows the rest of string when i did put a null character. It should show output as 200000 and length has 6.