Reverse and gets | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Reverse and gets

I was trying to learn some string functions but i noticed that strrev() and gets() does not work in the SoloLearn playground. Does anyone know why?

8th Jan 2020, 2:32 PM
Keith Alcantara
Keith Alcantara - avatar
3 Answers
+ 3
as you have started learning c++ you can use reverse function to reverse string in c++ #include <iostream> #include <algorithm> using namespace std; int main() { string s="reverseit"; reverse(s.begin(),s.end()); cout<<s; return 0; }
8th Jan 2020, 3:27 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
Both functions are removed from C. You can still use fgets() as an alternative to gets(), but you have to implement yourself a function to reverse a string.
8th Jan 2020, 2:57 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
strrev isn't included in the <strings.h> header for linux, best try to implement one such as the attached code. As for gets, its not recommended due to memory possible overwritten out of bounds. https://code.sololearn.com/cO26g6EB47ma/?ref=app
26th Jan 2020, 11:27 AM
0x6176696c61
0x6176696c61 - avatar