+ 10

Why this code can't be used as a replace of strrev function

I know strrev function will not work in sololearn. So I made a replace function for it but it is not giving the answer can any one correct the mistake. Here is my try. https://code.sololearn.com/cB5mRRQNpgS1/?ref=app

18th Jul 2020, 6:16 AM
Puthur Harthik
9 ответов
+ 3
https://code.sololearn.com/cAksCt6hQbO4/?ref=app
18th Jul 2020, 6:36 AM
Dmitriy Trifonov
Dmitriy Trifonov - avatar
+ 7
Thanks Djivs for your help
18th Jul 2020, 6:50 AM
Puthur Harthik
+ 6
Nice idea Djivs . But why should we set size for a pointer to use it. Can't we use directly
18th Jul 2020, 6:40 AM
Puthur Harthik
+ 5
Sorry I didn't understand what you are saying Djivs can you change it in my code and keep the correct code
18th Jul 2020, 6:30 AM
Puthur Harthik
+ 2
It seems like you didnt set char *c size, but not what I said before
18th Jul 2020, 6:38 AM
Dmitriy Trifonov
Dmitriy Trifonov - avatar
+ 2
Sadly, no, because in C we have to allocate memory first. We need to work with memory very carefully :)
18th Jul 2020, 6:48 AM
Dmitriy Trifonov
Dmitriy Trifonov - avatar
+ 2
You are welcome :)
18th Jul 2020, 6:51 AM
Dmitriy Trifonov
Dmitriy Trifonov - avatar
+ 2
Puthur Harthik, that's because you declared a new variable of type pointer to a char but you haven't initialized it, which means you try to access an undefined memory location.
18th Jul 2020, 11:30 AM
Vasile Eftodii
Vasile Eftodii - avatar
+ 1
You need to do reverse cycle only for i <= k/2 Example: abcd 0 dbca 1 dcba 2 - already reversed dbca 3 abcd 4
18th Jul 2020, 6:27 AM
Dmitriy Trifonov
Dmitriy Trifonov - avatar