Problem link : CD202
My code : CD202
Because you’re putting null character (’\0’) too early. As a result it prints only “ra” in the output for the sample input given. Cross check your code with the input example. Null character means terminating the string right there.
See this solution for example, it is similar. You can keep an alternate array to hold the answer.
What if I use something else instead of \0
? That shouldn’t terminate the string.
Yes but then that will be reflected in your output, right? That is why I asked you to look the alternate solution. See how he has skipped the characters in ans array. (i += 2
)
I don’t understand thius statement from his code : ans[j++]=str[i];
. Which element is ++j
?
See, initially j was zero. Now ans[j++] = str[i]
means copy the character at ith position in str to jth position in ans and then increment j.
This entire work is done in the single line. And then a check is made for a vowel, if there is a vowel then a simple skip jump is made of two steps as explained in my previous comment.