Here's a part of my code:
int main() {
int l,i;
cin>>l;
char *ch = new char[l];
for(i=0;i<l;i++)
cin>>ch[i];
return 0;
}
I want my input to be something like "A computer" or any other sentence so that I can replace each space character with a "%20". When I tried to input a sentence, I realised that I couldn't input the spaces. My character array ends up storing all the other character but it omits the spaces.
Note: I am aware that it can easily be done using strings in c++ but I want to use a character array only. My intention is to know if it is possible and if yes, how can it be done?
Edit: The solution to this question: std::cin input with spaces? doesn't work for me. I have tried this: cin.getline(ch,l); But I couldn't manipulate my sentence when I tried to access the space character or add '%', '2', '0' using ch[i]. I don't understand how cin.getline() can be used here.