In this question when pie is getting replaced by 3.14, then after 3.14 it is giving some garbage value.
Here is the code given below.
Doubt in Replace pie
Hello @ratulhans,
There are three issues with your code:
- Incomplete Output:
Example:
1
xpipipxpixx
Your Output:
x3.14
Expected Output:
x3.143.14px3.14xx
Solution:
else{ b[j]=a[i]; j=j+1; i=i+1; }
You are missing braces, which causes unwanted increment in i and j.
Thus, causing wrong output.
-
It will fail for longer strings:
It is mentioned in the code, 0 <= len(str) < 1000
Also, for every “pi” two extra characters are added “3.14”
Problem:
char a[100],b[100];
Solution:
char a[1000],b[3000]; -
When you take input using cin, the compiler adds “/n” i.e. endline corrector in the input stream.
And after reading input from stream, it does not removes “/n” from the stream.
Thus, when you would use cin.getline() function:
It will first read “/n”, causing a blank line in the output.
I have modified your Code:
Give a like, if you are satisfied.